|
-
Oct 12th, 2002, 11:19 AM
#1
Thread Starter
Member
Visual C++ DLL won't work with VB
Didn't know where to post this as it's both VB and VC code, heres goes:
I have a DLL which contains this function:
void _stdcall cryptArray(unsigned char *bArray, long bArrayLen)
{
for (long i=0; i<=bArrayLen; ++i)
{
bArray[i]=bArray[i]^5;
}
}
To use this is Visual Basic, I call it with a procedure similar to this:
Public Declare Sub cryptArray Lib "C:\My Documents\Visual C++\XorEnc DLL\Debug\XorEnc DLL.dll" (Bytes As Byte, NumBytes As Long)
Dim Bytes(0 To 3) As Byte
For t = 0 To 3
Bytes(t) = t
Next
cryptArray Bytes(0), 4
When I do this I get a "Vb6 has caused an error..." in the above DLL.
Can anyone see where I've gone wrong?
-
Oct 12th, 2002, 01:48 PM
#2
Fanatic Member
strings need to BSTR, not char *
also.
Code:
extern "C" {
void _stdcall cryptArray(BSTR bArray[], long bArrayLen)
{
for (long i=0; i<=bArrayLen; ++i)
{
(LPCSTR)bArray[i]=(LPCSTR)bArray[i]^5;
}
}
}
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Oct 13th, 2002, 06:16 AM
#3
Thread Starter
Member
I still get the same error. I'm not sure if the cause is in the visual basic part (particularly the Public Declare), or whether it's the C code.
Can anyone else help?
-
Oct 13th, 2002, 11:26 AM
#4
Re: Visual C++ DLL won't work with VB
Originally posted by CactusCat
Didn't know where to post this as it's both VB and VC code, heres goes:
I have a DLL which contains this function:
void _stdcall cryptArray(unsigned char *bArray, long bArrayLen)
{
for (long i=0; i<bArrayLen; ++i)
{
bArray[i]=bArray[i]^5;
}
}
To use this is Visual Basic, I call it with a procedure similar to this:
Public Declare Sub cryptArray Lib "C:\My Documents\Visual C++\XorEnc DLL\Debug\XorEnc DLL.dll" (ByVal Bytes As Long, ByVal NumBytes As Long)
Dim Bytes(0 To 3) As Byte
For t = 0 To 3
Bytes(t) = t
Next
cryptArray VarPtr(Bytes(0)), 4
When I do this I get a "Vb6 has caused an error..." in the above DLL.
Can anyone see where I've gone wrong?
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.
-
Oct 13th, 2002, 11:46 AM
#5
Thread Starter
Member
THANK YOU! I'd forgotten about the VarPtr function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|