Results 1 to 7 of 7

Thread: C++ types in VB ?

  1. #1

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391

    C++ types in VB ?

    Hi, I found this Base64 dll written in C++ but I need to call it's functions from VB. Most of the variable types I can figure out and get to work, but there's a couple that I don't know how to translate into VB and could use some help. The list is below.

    Code:
    UINT cb  =  ByVal cb As Long
    LPCTSTR lpInput  =  ByVal lpInput As String    ?
    LPUINT lpEqualSigns  =  ByRef lpEqualSigns As Long  ?
    LPCBYTE lpInput  =  ?? (supposed to be the string to encode)
    LPTSTR lpOutput  =  ?? (supposed to be the output buffer, I'm guessing it would be a string of spaces)
    LPCTSTR lpInput  =  ??
    LPBYTE  lpOutput  =  ??
    BASE64CALLBACK lpEndCallback  =  ??
    LPVOID lpvParam  =  lpvParam As Any ?? (ByVal/ByRef?)
    If anyone can shed some light on this I would really appreciate it. I'm trying to get in contact with the author but I don't know if I will be able to.
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This is a guess by the way

    UINT cb = ByVal cb As Long
    LPCTSTR lpInput = ByVal lpInput As String ?
    LPUINT lpEqualSigns = ByRef lpEqualSigns As Long ?

    LPCBYTE lpInput = ByRef byteArray() As Byte
    LPTSTR lpOutput = ByRef strOutput As String
    LPCTSTR lpInput = ByVal strInput As String
    LPBYTE lpOutput = ByRef byteOutput() As Byte
    BASE64CALLBACK lpEndCallback = ByVal lpEndCallBack As Long



    strOutput would probably have to be made a big long string of spaces before you start.
    byteArray() and byteOutput() are both byte arrays

    And lpEndCallBack is a pointer to a function

  3. #3

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Thanks for the input plenderj,

    I tried byte arrays but vb is still crashing (getting invalid page faults, yay!).

    Does anyonek now if there some special way to place a string into a byte array that needs to be done? I just looped through getting the Asc() of each char. lpOutput is a null-terminated string of spaces.

    This is the declaration in my module
    VB Code:
    1. Declare Function Base64EncodeA Lib "Base64" (lpInput() As Byte, _
    2. ByVal cbInput As Long, ByRef lpOutput As String, _
    3. ByVal cbOutput As Long) As Boolean

    And here it is in C++
    Code:
    BOOL BASE64API Base64EncodeA(LPCBYTE lpInput, UINT cbInput, LPSTR lpOutput, UINT cbOutput)
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    To create byte arrays and vice-versa.

    VB Code:
    1. Public Sub StrToAry(ByVal strIn As String, ByRef aryOut() As Byte)
    2.     aryOut = StrConv(strIn, vbFromUnicode)
    3. End Sub
    4.  
    5. Public Sub AryToStr(ByRef aryIn() As Byte, ByRef strOut As String)
    6.     strOut = StrConv(aryIn, vbUnicode)
    7. End Sub


    And the invalid page fault could be caused by an invalid pointer to a function.
    That always crashes applications when it isn't done correctl.

  5. #5

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    I tried converting to unicode, still no luck.

    And the invalid page fault could be caused by an invalid pointer to a function.
    Does that mean you think the problem would be an invalid pointer in the dll iself, or one of my parameters is an invalid pointer?
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I would have to say its probably a problem on your side

    To get a pointer to a function :

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim myPointer As Long
    3.     myPointer = getAddressOf(AddressOf Me.myFunction)
    4. End Sub
    5.  
    6. Public Function getAddressOf(ByVal n As Long) As Long
    7.     getAddressOf = n
    8. End Function
    9.  
    10. Public Function myFunction()
    11.     '' some code here
    12. End Function

    So you would pass myPointer to the DLL.
    Now, I don't know what its supposed to do with the pointer.
    I'd guess it just calls it after its done.
    But that might not be the case.
    It could be that you have to have a properly formatted function to accept parameters back from the DLL.

    You'd really have to check the documentation of the DLL itself.

  7. #7

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Hmm ok, I guess I'll have to try and get more information from the author..if I can track him down. Thanks anyways plenderj.
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

Posting Permissions

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



Click Here to Expand Forum to Full Width