Link to home
Start Free TrialLog in
Avatar of cdoggett
cdoggett

asked on

Creating a ATL Library class

Greetings, I am new to creating ATL libs and have a question about the following code.  I am converting this from a VC 6 dll to a VC 6 ATL dll.  So I can use it with C#.

The library will consist of the 5 functions listed below.  Only two will be called by the client, SetDocument and the CallJScript function.  The other will be used by the library internaly.  Using the Class View wizard and chosing Add Method.  How do I declare the internal functions vs. the external (public) functions.  

Also could someone please help me with the IDL statements.  Especially for CStringArray and do I reference it the same way in the library function?  

      bool SetDocument(IDispatch* pDisp);
      bool CallJScript(const CString strFunc,const CStringArray& paramArray,CComVariant* pVarResult = NULL);

      LPDISPATCH GetHtmlDocument() const;
      const CString GetLastError() const;

Thanks in advance!!!
Avatar of jkr
jkr
Flag of Germany image

You can't use MFC classes as arguments in IDL. I'd suggest to replace that by the proper types, such as 'BSTRs' or a variant of type 'BSTR'. 'strings' are also possible, e.g.

    bool SetDocument(LPDISPATCH pDisp);
    bool CallJScript([in, string] PCHAR  strFunc,[in, ref, size_is(m)] PCHAR paramArray, int m, [out, optional] VARIANT* pVarResult);

    LPDISPATCH GetHtmlDocument() const;
    [unique] char * GetLastError() const;
Avatar of cdoggett
cdoggett

ASKER

Excellent, one question though, how do I use paramArray though.  I noticed the extra argument m which delcares the size.  Could you show me a small code sample??    Thanks and Happy Forth!

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When I used PCHAR as you suggested I got a compiler error

error MIDL2025 : syntax error : expecting a type specification near "PCHAR"

[id(2), helpstring("method CallJScript")] HRESULT CallJScript([in] PCHAR strFunc, [in, ref, size_is(m)] PCHAR paramArray, [in] int m, [out, optional] VARIANT* pVarResult);

I changed it to use BSTR and it compiled OK.  Which is better?  If I go with BSTR, will that change the usage of the code below you suggested??

CStringArray as;
as.SetSize(m);

    for (int i = 0; i < m; ++i) cs.SetAt(i, paramArray[i]);

Thanks
Sorry, almost missed that...

Actually, 'PCHAR' (as one of the 'Win32 Simple Data Types') should be defined in 'winnt.h' - that's odd, MIDL should definitely know it. In fact, both will/should work, BSTRs lacking the advantage of having the marshalling layer provide a real 'char*'