CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2002
    Posts
    290

    Need help on call COM method from VBScript.

    I have developed a COM DLL under VC++ 6.0. The project is created by COM wizard.The interface's name is ISMA. Then I add a method to it.The code is
    interface ISMA : IDispatch
    {
    [id(1), helpstring("method IFInitInterface")] HRESULT IFInitInterface(DWORD dwCodeProtocol, DWORD dwDriverProtocol, LPCTSTR pDriverParam);
    };

    STDMETHODIMP CSMA::IFInitInterface(DWORD dwCodeProtocol, DWORD dwDriverProtocol, LPCTSTR pDriverParam)
    {
    // TODO: Add your implementation code here
    return m_impClass.Test();
    return S_OK;
    }
    --------------------------


    <%
    set obj=Server.CreateObject("SMACOM.SMA.1")
    %>
    <HTML>
    <%
    i = obj.IFInitInterface(0,0,"1")
    %>
    </HTML>

    The error is IFInitInterface is not a VBScript supported Automation type.
    Error code is 800a01ca.

    Thanks a lot.

  2. #2
    Join Date
    Apr 2004
    Posts
    76
    Hi sm_ch,

    Since you are using vb script, everything needs to be a VARIANT.

    Return HRESULTs.

    To return a value to a client, you need a [out, retval] parameter.

    Use BSTRs instead of LPCTSTR.

    Note that VBScript requires VARIANTs - if you have a smart Automation aware language such as VB or Visual Java, you could actually pass BSTR*'s as parameters/return values.

    Something similar to below should work...

    See http://msdn.microsoft.com/library/de...ion_topics.asp and http://msdn.microsoft.com/library/de...chap7_5alv.asp

    See also http://msdn.microsoft.com/library/de...chap6_7zdz.asp for the VARIANT structure.

    Jeff


    Code:
    [id(1), helpstring("method Test")] HRESULT
    Test( [in] VARIANT* param, [out, retval] VARIANT* retval );
    And

    Code:
    STDMETHODIMP CTest::Test(VARIANT* param, VARIANT* retval)
    {
        if( NULL == param || param->vt != VT_BSTR )
        {
            return E_INVALIDARG;
        }
    
        if( NULL == retval || retval->vt != VT_BSTR )
        {
            return E_INVALIDARG;
        }
    
        HRESULT hr = SysFreeString( *retval );
    
        if( FAILED( hr) )
        {
            return hr;
        }
    
        USES_CONVERSION;
        LPCTSTR szParam = OLE2T(param);
    
        // tinker with szParam
    
        *retval = SysAllocString( szParam );
    
        if( NULL == *retval )
        {
            return E_MEMORY;
        }
    
        return S_OK;
    }
    Last edited by jwalto1; July 13th, 2004 at 03:54 PM. Reason: Added Comment

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