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.
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:
Function MyCallback(ByVal param As Long, ByRef lpParam As Any) As Long
'blabla, lpParam is what you passed at the LPVOID parameter
'if you passed 0 then DON'T USE THIS!
End Function
'Function call
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.
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 =\
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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:
Dim coder As New CBase64Coder
Dim result() As Byte
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.
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.
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.
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.
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.
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:
Option Explicit
Private Sub Command1_Click()
Dim coder As New CBase64Coder
Dim X As Variant
'This is the line that raises the error
coder.DecodeStringToByteArray Text1.Text, X
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.
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.
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.
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.
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.