06-07-2010 09:45 AM
I am calling a DLL (ActiveX)that has several properties requiring string arguments as inputs.
For example:
HRESULT _stdcall SerialNumber([in] BSTR Value );
The problem that I am running into is that, as you know, LabVIEW prepends the length of the string to the string value. The DLL is expecting a C-style string and there is an error because of the extraneous bytes at the beginning of the string.
How can LabVIEW sucessfully call an ActiveX property with a BSTR input? Is there a way to convert to a C-style string?
Thanks!
06-07-2010 10:52 AM - edited 06-07-2010 10:54 AM
You communicate with an ActiveX object, not with a DLL directly! Thus you don't have to convert your string, LV does it for you. All data types used in communication between ActiveX and LV must be automation compatible.
The only automation compatible string type is BSTR, you have no option to pass a C string to an ActiveX node directly.
There must be another problem within your ActiveX call. Your error is not a BSTR-related issue.
06-07-2010 11:20 AM
You communicate with an ActiveX object, not with a DLL directly!
Yes, thank you, I did not state that clearly.
Thus you don't have to convert your string, LV does it for you.
Actually, I have the source code (written in Delphi) for the ActiveX object. Placing a breakpoint shows the string length bytes included at the beginning of the string. So, if by conversion, you mean removing the string length from the beginning of the string, clearly it's not doing so. I also call these properties with applications I wrote in C# and Delphi and none have this issue.
All data types used in communication between ActiveX and LV must be automation compatible. The only automation compatible string type is BSTR, you have no option to pass a C string to an ActiveX node directly.
Yes and a BSTR is what is used.
There must be another problem within your ActiveX call. Your error is not a BSTR-related issue.
Well, it's a simple call and it works with two other programming languages so I'm not sure what the problem could be that isn't directly related to LabVIEW and the way that a LV string is passed to a ActiveX property with a BSTR input.
Thank you for your response.
06-07-2010 01:50 PM
OK, let's dig a little deeper: What error do you get? Probably the HRESULT or the error message will help.
Actually, I have the source code (written in Delphi) for the ActiveX object. Placing a breakpoint shows the string length bytes included at the beginning of the string. So, if by conversion, you mean removing the string length from the beginning of the string, clearly it's not doing so.
What you see in the debugger is correct: BSTRs are in fact Unicode strings with the string length prepended.
There are special allocation functions in the win32 API to create them. Every ActiveX client program has to use
these functions.
Well, it's a simple call and it works with two other programming languages so I'm not sure what the problem could be that isn't directly related to LabVIEW and the way that a LV string is passed to a ActiveX property with a BSTR input.
There can be other issues as well, ActiveX is not the simplest thing on earth 🙂 Let's look at the error message.