Fire Event BSTR with NULL character
-
Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.
-
Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.
Note: Without seeing any of your code, I'm just guessing... It's probably because when you create the BSTR, you let it count characters to determine its length, rather than telling it what the length actually is. Any string length function in C/C++ will see a NULL as the end of string. So, create your BSTR like this, telling it what its length is:
BST b = SysAllocStringLen(L"ABC\0XYZ", 7);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!
-
Note: Without seeing any of your code, I'm just guessing... It's probably because when you create the BSTR, you let it count characters to determine its length, rather than telling it what the length actually is. Any string length function in C/C++ will see a NULL as the end of string. So, create your BSTR like this, telling it what its length is:
BST b = SysAllocStringLen(L"ABC\0XYZ", 7);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!
Still I am getting only ABC in VB So please tell me how to send full string. I am getting what you have told me. but I want to transfer this full string from vc to vb. So please tell me the solution It's very urgent Thanks for help.
-
Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.
As I recall you won't be able to do as you want, either the ATL Event Wizard generated code sees the internal NULL and loses the rest (even with the BSTR length set) or VB will see a a NULL terminated string. I'm pretty sure You'll have do do more one way or the other. Maybe pass an array of characters?
-
Still I am getting only ABC in VB So please tell me how to send full string. I am getting what you have told me. but I want to transfer this full string from vc to vb. So please tell me the solution It's very urgent Thanks for help.
This begs an obvious question: can VB handle strings with embedded NULLs? Many of C's CRT functions such as
wcscmp
can't for example.Steve
-
Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.
The NULL character is your problem. Try replacing it with some other unique Unicode character which both parts of your application can recognise. Alternatively put the box character in your source string in the first place.
It's time for a new signature.