PDA

Click to See Complete Forum and Search --> : Passing binary strings with ActiveX


ExciteMouse
Dec 21st, 2000, 11:42 AM
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

ExciteMouse
Dec 21st, 2000, 01:06 PM
and i want to pass it back to the VB user as 'String' not as a byte array.

parksie
Dec 22nd, 2000, 12:26 PM
If you pass it back as a null-terminated char* then VB will be able to interpret it as a string.

ExciteMouse
Jan 3rd, 2001, 11:31 AM
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?

parksie
Jan 3rd, 2001, 12:10 PM
I'd probably have a C prototype similar to this:

void GetData(unsigned char** ppubData, unsigned long *pulLength);


Then in VB:

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.

ExciteMouse
Jan 5th, 2001, 11:12 PM
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:


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*