Problem description:
Previously, we had an interface similar to int winapi readbiosversion (byte * bios, ulong size, char * version). This interface is packaged in DLL and operated on the underlying BIOS. The person who provides the interface provides 32-bit and 64-bit DLL sets. Our applicationProgramIt is 32bit. 64bit needs to be called to run on 64bit OS. Therefore, our solution is to use the com outside the process described in the previous article. But the problem arises. I provide an interface in COM to encapsulate this interface, for example, int
Winapi readbiosversion (BSTR bios, ulong size, BSTR * ver );
At this time, we are faced with the problem of converting the content of the byte array to the BSTR type and vice versa.
The solutions provided by netizens are as follows:
Reply: solution 1:
_ Bstr_t STR = (char *) bytearray; BSTR = Str. getbstr ();
Solution 2:
Ccomvariant Var = (char *) bytearray; BSTR = var. bstrval;
Solution 3:
Uses_conversion; BSTR = a2bstr (char *) bytearray );
I found a string truncation problem in my project. If the byte array contains a normal string, the Netizen's solution should be fine. It is a coincidence that the byte array contains empty characters, which gives me the motivation to write this topic.
My solution is:
BSTR = sysallocstringlen (null, dwsize/2); memcpy (BSTR, pdata, dwsize );
Otherwise, the BSTR type is converted to a byte array
Lpbyte Lp = new byte [size]; memcpy (LP, bios, size );