CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2005
    Posts
    27

    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.

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    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);

  3. #3
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930

    Re: Using ActiveX created in VB

    This is good enough..
    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

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Using ActiveX created in VB

    Quote 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 ?

  5. #5
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930

    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

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    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
  •  





Click Here to Expand Forum to Full Width

Featured