|
-
Dec 21st, 2000, 12:42 PM
#1
Thread Starter
Lively Member
hello.
I am making an ActiveX control in MFC that is supposed to work with Visual Basic.
I want to make a function in the control that will return a binary string of non-constant size (unsigned char*)
Let's just make the example easy...
In the control there is a function called:
GetFileData(LPCSTR FileName)
how would i return the innards of the file to the user correctly? and this is a binary file, not a text file.
thanks in advance
-
Dec 21st, 2000, 02:06 PM
#2
Thread Starter
Lively Member
one more thing
and i want to pass it back to the VB user as 'String' not as a byte array.
-
Dec 22nd, 2000, 01:26 PM
#3
Monday Morning Lunatic
If you pass it back as a null-terminated char* then VB will be able to interpret it as a string.
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
-
Jan 3rd, 2001, 12:31 PM
#4
Thread Starter
Lively Member
but since this is a binary string, it may contain nulls in it allready. I want to return a varible declared as string in VB that is basically Unsigned Char* in C++.
does that make sence?
-
Jan 3rd, 2001, 01:10 PM
#5
Monday Morning Lunatic
I'd probably have a C prototype similar to this:
Code:
void GetData(unsigned char** ppubData, unsigned long *pulLength);
Then in VB:
Code:
Declare Sub GetData ... (ByRef ppubData() As Byte, ByRef pulLength As Long)
Dim dat() as Byte
Dim len as long
GetData dat, len
I can't check that at the moment, but I think the theory's fairly sound.
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
-
Jan 6th, 2001, 12:12 AM
#6
Thread Starter
Lively Member
Finally got it.
ok if anyone cares, this is how you do it with MFC C++
in the ActiveX control or DLL you setup a function like so:
Code:
BSTR ReturnBinaryString()
{
CString strResult;
//Buffer the string to how ever long
strResult.GetBufferSetLength(10);
//theres a null at position 3 of the 10 byte string
strResult.SetAt(3, '\0');
//return a SYSSTRING so you do not get dealloction leak
//(System will take care of deallocation for you)
return strResult.AllocSysString();
//now in VB this will return as a string of 10 bytes with a null at position 3.
}
*whew*
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
|