-
January 25th, 2006, 05:43 PM
#1
Using ActiveX created in VB
I have an ActiveX control created in Visual Basic that I'm trying to use in my Visual C++ app. I'm having a little trouble with one of the functions of the control.
The definition of the function looks like this:
Code:
Public Function GetStrVal(ByRef strVal As String) As Long
I have an instance of this control and I'm trying to call this function but I'm getting a compiler error. Here is how I'm using it:
Code:
CString str;
long lIndex = m_obj.GetStrVal(str);
which results in the following compiler error:
Code:
cannot convert parameter 1 from 'class CString' to 'unsigned short ** '
I found a way around it but I don't like it much:
Code:
_bstr_t bstrTemp;
BSTR Temp = bstrTemp;
long lIndex = m_obj.GetStrVal(&Temp);
Can anyone tell me the "correct" way or at least a "better" way of doing this? I can change either the VB side or the C++ side.
-
January 25th, 2006, 06:00 PM
#2
Re: Using ActiveX created in VB
This is good enough..
Code:
BSTR Temp;
long lIndex = m_obj.GetStrVal(&Temp);
//use the Temp
//when done, free it
SysFreeString(Temp);
-
January 26th, 2006, 03:27 AM
#3
Re: Using ActiveX created in VB
No, it's not. The variable should be initialized because the VB's ByRef parameter is [in,out] one.
Code:
BSTR Temp = NULL; // or SysAllocString(...)
With best wishes,
Vita
-----------------------
Russian Software Development Network -- http://www.rsdn.ru
-
January 26th, 2006, 08:29 AM
#4
Re: Using ActiveX created in VB
Originally Posted by Vi2
No, it's not. The variable should be initialized because the VB's ByRef parameter is [ in,out] one.
Code:
BSTR Temp = NULL; // or SysAllocString(...)
Thanks for correcting.. Don't know about VB
Anyways, in that case, how would Temp = NULL work ? I would assume VB would expect a valid BSTR if it is an in param , right ?
-
January 26th, 2006, 08:41 AM
#5
Re: Using ActiveX created in VB
Anyways, in that case, how would Temp = NULL work ? I would assume VB would expect a valid BSTR if it is an in param , right ?
The C's NULL is the valid BSTR value and equals the VB's vbNullString. There is an equivalence for "" and vbNullString: both are the empty strings.
With best wishes,
Vita
-----------------------
Russian Software Development Network -- http://www.rsdn.ru
-
January 26th, 2006, 09:06 AM
#6
Re: Using ActiveX created in VB
OK. Just wanted to know. Because if it is a [in,out] , then VB would have to either SysFree/SysRealloc the in param. I beleive VB would handle this case.
Thanks for the info, BTW
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|