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

    ATL project (simple COM server)

    I created simple COM out-of-proc EXE server (CLSCTX_LOCAL_SERVER) using ATL project in Microsoft Visual Studio 2008. Also I added my class and my interface to the project. I don't need Automation, so I don't want to derive from IDispatch and my interface is not dual interface. Here is CMyClass definition in the header file:

    Code:
    #pragma once
    #include "resource.h"       // main symbols
    
    #include "MyServer_i.h"
    
    class ATL_NO_VTABLE CMyClass :
    	public CComObjectRootEx<CComSingleThreadModel>,
    	public CComCoClass<CMyClass , &CLSID_MyClass>,
    	public IMyClass
    {
    public:
    	CMyClass()
    	{
    	}
    
    DECLARE_REGISTRY_RESOURCEID(IDR_MYCLASS)
    
    DECLARE_NOT_AGGREGATABLE(CMyClass)
    
    BEGIN_COM_MAP(CMyClass)
    	COM_INTERFACE_ENTRY(IMyClass)
    END_COM_MAP()
    
    
    DECLARE_PROTECT_FINAL_CONSTRUCT()
    
    	HRESULT FinalConstruct()
    	{
    		return S_OK;
    	}
    
    	void FinalRelease()
    	{
    	}
    
    public:
    
    	// IMyClass interface
    	STDMETHOD(CreateMyObject)(ULONG ulType, PMYSTRUCT pMyStruct, ULONG* ulObjID);
    };
    
    OBJECT_ENTRY_AUTO(__uuidof(MyClass), CMyClass)
    MYSTRUCT structure (and PMYSTRUCT pointer) is defined in project's *.idl file and resides in MyServer_i.h header file generated by MIDL compiler. CreateMyObject method is defined in correspondent *.cpp file of CMyClass.
    Well, this project is compiled and linked perfectly without any problems.
    My problem is that when I try to call CoCreateInstance of CMyClass COM object from different client appication and requesting IMyClass interface it fails to do so (returns NULL pointer). When I open OleView.exe application It shows My class in registered objects, but there is no IMyClass interface in the object. The interesting thing is that when I look to the type library (again using OleView) I can see IMyClass interface, CMyClass object and MYSTRUCT structure. I'm thinking might be COM_INTERFACE_ENTRY(IMyClass) macro somehow doesn't put IMyClass interface into CMyClass object interface MAP.

    BTW if I use dual interface (IMyClass is derived from IDispatch using IDuspatchImpl) all is working (I can get IMyClass interface from client application). But I don't need to support IDispatch.
    Any ideas?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ATL project (simple COM server)

    You'll need to generate and register a proxy/stub dll. Sorry, I've forgotten how to do this (as it's been a while).

  3. #3
    Join Date
    Jan 2004
    Posts
    13

    Re: ATL project (simple COM server)

    Thank You for your answer.
    Actually I don't want to implement my own marshaling.
    I want to use standard marshaling.
    As I know for dual interfaces (the interfaces inherited from IDispatch)
    oleaut32.dll proxy/stub dll handles all burden related to marshaling.
    Is it possible to use oleaut32.dll proxy/stub for non-dual (Custom) interfaces?
    Or might be there is other standard proxy/stub DLL for non-dual (Custom) interfaces?
    I can remove PMYSTRUCT custom-defined structure pointer from CreateMyObject method of IMyClass interface and use only Automation compatible types such as VARIANT, SAFEARRAY and so on.
    The thing I need is not inherit from IDispatch (I really don't need it) and use some standard marshaling.
    Is it possible?

  4. #4
    Join Date
    Jan 2004
    Posts
    13

    Re: ATL project (simple COM server)

    It seems the problem is solved. Actually it was not a problem.
    ATL COM Wizard made a proxy/stub DLL project, I just needed to build the DLL and register it.
    And now I'm wondering why ATL COM Wizard does not properly set the project dependences, so after I build my basic COM Server project with DEBUG configuration, its project/stub DLL project also builds and registers proxy/stub DLL? I suppose this is intuitive...

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ATL project (simple COM server)

    Quote Originally Posted by Miran View Post
    And now I'm wondering why ATL COM Wizard does not properly set the project dependences, so after I build my basic COM Server project with DEBUG configuration, its project/stub DLL project also builds and registers proxy/stub DLL? I suppose this is intuitive...
    The reason is that not everyone wants/needs a proxy. Glad to hear that you got it solved.

  6. #6
    Join Date
    Jan 2011
    Posts
    1

    Cool Re: ATL project (simple COM server)

    Where is your interface source code? I am pretty sure your interface is automation compatible and I think you should use the oleautomation attribute for your interface. This will enable the universal marshaling for your interface and then you really don't need the PS project and ps dll.

Tags for this Thread

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