dcsimg
Results 1 to 5 of 5

Thread: help to translate c to vb6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    16

    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
    31,969

    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,541

    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
    Addicted Member
    Join Date
    Jun 2015
    Posts
    253

    Re: help to translate c to vb6

    it can be helpful to compile your vb6 exe with debug info,

    since the C and H files are just for a demo C exe not the dll source.
    will have to compile vb exe then use ollydbg or similar as your native debugger.

    it would probably be worth the time to make a small C test dll using the struct and
    target prototype so you can test between vb and C using the visual studio debugger
    in source mode.

    You can compare structs in memory and data passed between the C test and VB test exe's

    If you have a vb array of structs I think you will be able to pass them in
    byval as long and use varptr(udtArray(0))

    fill out two structs with test values easily read in hex like 0x11223344
    and 0x55667788 etc then look at them in memory. To make sure no unexpected padding
    is being applied and that they match structs filled out in C either seralized to disk or in memory.

    you could also just always pass in a direct pointer to an individual PW_GetData with
    piNumParam always set to 1.

    The C fields such as

    char szPrompt[84];

    are going to require the vb type declare be something like szPrompt as string * 84
    to get a fixed size buffer. You can probably serialize the vb udt to disk and then load it from
    C in the same manner to test the struct loading / unloading / compatability.

    some bits of the vb struct are off like

    char szMascaraDeCaptura[41];
    szMascaraDeCaptura As String

    actually the vb type def needs rework. you have extra fields and out of order fields.

    I am not entirely sure if things like a_MarshalAs(PWMENU_MAXINTENS) As String * 84 is
    going to pass to C as intended. good chance it might actually..but make sure to inspect memory.

    definitely make the c test dll.

    I would expect 1-3 days to get it working
    Last edited by dz32; Oct 10th, 2018 at 05:54 AM.

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

    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