dcsimg
Results 1 to 5 of 5

Thread: help to translate c to vb6

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    45

    help to translate c to vb6

    Help to translate c to vb6

    extern Int16 PW_EXPORT PW_iInit (const char* pszWorkingDir);
    extern Int16 PW_EXPORT PW_iNewTransac (Byte bOper);
    extern Int16 PW_EXPORT PW_iAddParam (Word wParam, const char *pszValue);
    extern Int16 PW_EXPORT PW_iExecTransac (PW_GetData vstParam[], Int16 *piNumParam);

    Private Declare Function PW_iInit Lib "PGWebLib" (ByVal hdc As String) As Integer
    Private Declare Function PW_iNewTransac Lib "PGWebLib" (ByVal hdc As Byte) As Integer
    Private Declare Function PW_iAddParam Lib "PGWebLib" (ByVal wParam As Integer, ByVal pszValue As String) As Integer
    Private Declare Function PW_iExecTransac Lib "PGWebLib" (ByRef pvstParam As Any, ByVal piNumParam As Integer) As Integer

    this = PW_iExecTransac, not working

    https://drive.google.com/open?id=1Sd...hx5hoxE6tlLRh_

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,293

    Re: help to translate c to vb6

    the parameter should be an array of type PW_GetData ... not "any" ... you need to declare a structure that matches what PW_GetData looks like, and pass an array of that type to the function.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,830

    Re: help to translate c to vb6

    Private Declare Function PW_iExecTransac Lib "PGWebLib" (ByRef pvstParam As Any, ByVal piNumParam As Integer) As Integer
    This one looks fishy to me, since the "original" c-function expects a Pointer in the second argument. Shouldn't that be "As Long"?
    As to the first argument: IIRC passing an array in C is passing the address of the first element (correct me if i'm wrong), so "ByRef As Any" should work.
    I agree with tg, that the OP still has to define a structure according to PW_GetData.

    Ah well, but maybe i just said a lot of BS right now...
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  4. #4
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    306

    Re: help to translate c to vb6

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:13 AM.

  5. #5
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: help to translate c to vb6

    The declares look good to me, they are close to how I would do them.
    As dz mentioned though - PW_GetData is way off... what's with all the extra MarshalAs members, and arrays where there should be a single string? Did you copy it from .NET ?

    This is at least the correct struct size. Whether or not is padded correctly will take more investigation.

    Code:
    Public Type PW_GetData
       wIdentificador As Integer
       bTipoDeDado As Byte
       szPrompt(0 To 84 - 1) As Byte
       bNumOpcoesMenu As Byte
       ' VB is column major
       'vszTextoMenu(0 To PWMENU_MAXINTENS - 1, 0 To 41 - 1) As Byte
       'vszValorMenu(0 To PWMENU_MAXINTENS - 1, 0 To 256 - 1) As Byte
       vszTextoMenu(0 To 41 - 1, 0 To PWMENU_MAXINTENS - 1) As Byte
       vszValorMenu(0 To 256 - 1, 0 To PWMENU_MAXINTENS - 1) As Byte
       szMascaraDeCaptura(0 To 41 - 1) As Byte
       bTiposEntradaPermitidos As Byte
       bTamanhoMinimo As Byte
       bTamanhoMaximo As Byte
       ulValorMinimo As Long
       ulValorMaximo As Long
       bOcultarDadosDigitados As Byte
       bValidacaoDado As Byte
       bAceitaNulo As Byte
       szValorInicial(0 To 41 - 1) As Byte
       bTeclasDeAtalho As Byte
       szMsgValidacao(0 To 84 - 1) As Byte
       szMsgConfirmacao(0 To 84 - 1) As Byte
       szMsgDadoMaior(0 To 84 - 1) As Byte
       szMsgDadoMenor(0 To 84 - 1) As Byte
       bCapturarDataVencCartao As Byte
       ulTipoEntradaCartao As Long
       bItemInicial As Byte
       bNumeroCapturas As Byte
       szMsgPrevia(0 To 84 - 1) As Byte
       bTipoEntradaCodigoBarras As Byte
       bOmiteMsgAlerta As Byte
       bIniciaPelaEsquerda As Byte
       bNotificarCancelamento As Byte
       bAlinhaPelaDireita As Byte
    End Type
    Things you have to consider now - ANSI vs Unicode strings and using StrConv() to convert them to VB Strings (which are 2 bytes per char), and figure out the best way to deal with the multidimensional strings. There are a lot of options, including using nested structs.
    Last edited by DEXWERX; Oct 10th, 2018 at 08:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width