Results 1 to 36 of 36

Thread: C++ -> VB variable types

  1. #1

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

    C++ -> VB variable types

    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.
    Last edited by brenaaro; Dec 3rd, 2002 at 08:56 AM.
    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
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    UINT = ByVal Long
    LPCTSTR, LPTSTR, LPCBYTE, LPBYTE = ByVal String
    LPVOID = ByRef Any, but you can declare it as ByVal Long and pass 0
    LPUINT = ByRef Long

    BASE64CALLBACK: pointer to a function in your main module. I don't know parameters and return type, but it would be something like:
    VB Code:
    1. Function MyCallback(ByVal param As Long, ByRef lpParam As Any) As Long
    2.   'blabla, lpParam is what you passed at the LPVOID parameter
    3.   'if you passed 0 then DON'T USE THIS!
    4. End Function
    5.  
    6. 'Function call
    7. FuncInDll ..., AdressOf(MyCallBack)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

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

    I got it to stop crashing VB and the function returns True (success)..the only problem now is that my outbuffer is getting filled with garbage instead of what it should be =\

    This is what the C++ function header looks like:
    Code:
    BOOL Base64Decode(LPCTSTR lpInput, LPBYTE lpOutput, UINT cbOutput)
    and this is how I declared in in VB:
    VB Code:
    1. Declare Function Base64DecodeA Lib "Base64" (ByVal lpInput As String, ByVal lpOutput As String, ByVal cbOutput As Long) As Boolean

    lpOutput is a string of cbOutput spaces and a nullchar at the end.
    Oh well, I'll keep trying to get info from the author.

    Thanks again!
    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
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Interestingly enough when I had to write a Base64 decoder the first thing I found was a Java class...
    Very useful I must say.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Hmm, I'm not sure if VB can call a Java class?
    Do you think a Java version would be faster than a C++ one?
    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
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    C will always be faster.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It can't. It was just something that came back to my mind.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But I also found a VB ActiveX, it would be easier for you to use.

    Try searching Google for Base64 decode or something like that.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Actually we already have a vb version to do the enc/dec. The encoding is not too slow, but decoding can take FOREVER (149 second to do 100kb).

    We really need to find the fastest way to do this because most of our client's machines are ancient and will be running other software.
    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.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Then I would write the whole app in C/C++...

    Of course that might not be an option for you for various reasons.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Cool, I wrote that DLL.
    But I did it so long ago that I highly suspect it sux.
    I suggest writing your own one in C/C++ or a better one in VB (C/C++ is more recommended, naturally).

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Or write an ActiveX in C/C++. Then it would be easy to use and still fast.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Hey hey Yonatan! =) Thanks for replying to my emails. I tried the VarPtr() method you suggested. I can get the output buffer filled, but it gets filled with garbage.

    I also tried converting vbUnicode/vbFromUnicode after calling the Base64Decode, and using StrPtr() as well but it's still gobble-dee-gook =\

    I would love to create my own in C++, the only problem is our whole office works in VB (we are kinda bunk), and I haven't done anything in C beyond the basics in over a year =(

    It may come down to us having to outsource some C developer to do it if I can't find another solution.
    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.

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Hey, this is an offer from me: I'll write it for free. I'd like to get familiar with the ATL library and I think this would be a good training. But I can't make any guarantees on when it will be ready.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  15. #15

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Wow CornedBee, that's a pretty generous offer to make! Well heck if you think you can do it then that would be awesome!

    All we would need is to be able to pass the contents of a file (or filepath, whichever is easier) and have it return the encoded base64 string, and to pass an encoded base64 string and return the unencoded contents (or write the unencoded contents to a specified filepath, whichever is easier =).

    Anyways, thanks again for the offer! Let me know if you do decide to take it up.
    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.

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Ok. I will write something that takes a string filled with encoded data as input and returns a decoded byte array, and something that takes a plain byte array as input and returns a string of encoded data.
    You will have to perform file operations yourself.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  17. #17

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    That's great! I'll send you my email address in case you need anything.
    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.

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is very tricky. I can't seem to create an [out, retval] SAFEARRAY parameter. MIDL always complains.
    VARIANTs on the other hand give me problems on the VB side: VB doesn't know what to expect and keeps giving me errors.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Hmm, I know Yonatan's version used an LPTSTR for the output buffer, which seemed to work just fine (on the Encode method). I don't know if that helps..
    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.

  20. #20
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But I write a real ActiveX object. Therefore I have to use Automation types. Since Base64 can be used to encode raw binary data I don't want to use a string (BSTR) to return the result, but rather a byte array. But I have to use a SAFEARRAY to do that.

    And still my VB client doesn't accept this code:
    VB Code:
    1. Dim coder As New CBase64Coder
    2. Dim result() As Byte
    3. result = coder.DecodeStringToByteArray TextInput.Text

    Did I get the VB syntax wrong there?
    It seems that it thinks DecodeStringToByteArray is a Sub even though it is a damned Function.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  21. #21

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    That looks like it should work. What error message is it giving you?
    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.

  22. #22
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It gives me a compilation error once I move away from the line, "Expected: End of expression", pointing at TextInput.Text
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  23. #23

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Try appending a Chr$(0) to the end of Text1.Text, I still get an 'invalid procedure call or argument' when I try to call the method.
    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.

  24. #24
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Have you registered the component and do you reference it?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  25. #25

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Yep, I placed the dll and the tlb in my winsys folder, regsvr32'd the dll successfully, and referenced it without a problem. Do I need to register the tlb?
    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.

  26. #26
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't know, VC++ does all registering for me...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  27. #27

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Well, I tried registering the tlb anyway but it failed =P
    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.

  28. #28
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Hmm, does the info come up while you're typing?
    Attached Images Attached Images  
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  29. #29
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    and
    Attached Images Attached Images  
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  30. #30

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Yep, everything comes up as normal. I declared a coder object as new CBase64Coder, and X as variant and pass them to the method. Here is the code I used in VB6:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim coder As New CBase64Coder
    5. Dim X As Variant
    6.  
    7. 'This is the line that raises the error
    8. coder.DecodeStringToByteArray Text1.Text, X
    9.  
    10. End Sub

    I really have no clue why it's not working. How did you define arByteOut in the dll?
    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.

  31. #31
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    VARIANT *arByteOut

    Very strange, that's the same code I use...

    The function would return an error if Text1.Text is an empty string, that might be it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  32. #32

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Text1.Text had "Text1", I also tried copying and pasting the base64 of an email attachment from outlook into Text1, but got same thing.

    I dont think the error is being returned from the function itself, vb is just raising a stink when I try to pass a string to the input and an Empty variant to the output...
    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.

  33. #33
    Lively Member
    Join Date
    May 2002
    Location
    Oregon
    Posts
    64
    Code:
    result = coder.DecodeStringToByteArray(TextInput.Text)
    Don't forget the paranthesis. In VB if I remember right you only omit them if you don't assign the return value to anything.

  34. #34

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    That is true, but I think that function call was from an earlier version of the dll. The current one accepts two parameters and does not return anything =\

    Code:
    'This is the new one
    DecodeStringToByteArray(strIn As String, arByteOut)
    One thing I just noticed. As I step through the code, it seems to take almost 1/2 of a second before raising the error. Almost as if the error were being generated from the dll.

    Question: What OS are you working on Corned Bee?
    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.

  35. #35
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I use Win2k.

    If Text1.Text contained "Text1" then it should raise an error, a "runtime error 5" to be exact. It does this every time when the string is invalid. I can change that if you want.

    Try this string, it's what I used for testing. It's "Hello, World!\n" encoded.
    SGVsbG8sIFdvcmxkIQ0K
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  36. #36

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    D'Oh..that would explain it.

    Ok I'll try that when I get back to theo ffice. You can keep the error 5 in there, now that I know what causes it I'll handle it on my end.
    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