LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem passing a string to an ActiveX property with a BSTR

I am calling a DLL (ActiveX)that has several properties requiring string arguments as inputs. 

 

For example:

HRESULT _stdcall SerialNumber([in] BSTR Value );

 

 

Nisupport.jpg 

 

 

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!

0 Kudos
Message 1 of 4
(4,137 Views)

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.

 

Message Edited by candidus on 06-07-2010 10:54 AM
0 Kudos
Message 2 of 4
(4,127 Views)

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.

0 Kudos
Message 3 of 4
(4,116 Views)
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.

 

0 Kudos
Message 4 of 4
(4,107 Views)