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

    CoCreateInstance returns E_NOINTERFACE

    I have been trying to solve this for quite a while now and still has no clue. I am hoping some COM expert would be able to help me out here.

    Basically, I have a COM server, which is an MFC app. The COM server implements a COM component. Below is what the code looks like.

    In myapp.cpp, I have:

    BOOL CHllwatchApp::InitInstance()
    {
    // Initialize OLE libraries
    if (!AfxOleInit())
    {
    AfxMessageBox(IDP_OLE_INIT_FAILED);
    return FALSE;
    }

    SCODE sc = ::CoRegisterClassObject( CLSID_HLLWATCH,
    &m_xMyClassFactory,
    CLSCTX_LOCAL_SERVER,
    REGCLS_MULTI_SEPARATE,
    &m_dwRegister );

  2. #2
    Join Date
    Apr 1999
    Posts
    3,585
    You need to provide more detail. Is the code you posted for the server or for the client? Where is the call to CoCreateInstance()?
    Gort...Klaatu, Barada Nikto!

  3. #3
    Join Date
    Aug 2002
    Posts
    173
    I hit the submit button accidently and I posted the entire code in the next post. For some reason, I dont see that post anymore.

    Rather than posting the code again, let me try to keep things brief this time.

    I have an out of proc COM server, which is an MFC app, which implements a single COM component. I am using MFC COM support (BEGIN_INTERFACE_PART/END_INTERFACE_PART macros in header file and BEGIN_INTERFACE_MAP/END_INTERFACE_MAP macros in CPP file). The COM server implements class factory, in addition to the single COM component. My component does not implement IDispatch interface, only a custom interface. The class that implements my component is derived from CCmdTarget.

    I have a C++ client which calls:

    HRESULT hr = ::CoCreateInstance(
    CLSID_MYCOMSERVER,
    NULL,
    CLSCTX_LOCAL_SERVER,
    IID_IMyInterface,
    (LPVOID FAR *) &pComponent );

    I traced the call to CoCreateInstance via debugger.

    The debugger shows that my class factory's CreateInstance method is called, which successfully creates my component.

    Then, QueryInterface method of my component is called 5 times by the COM library: once each for IID_IMarshal, IID_IStdMarshalInfo, IID_IExternalConnection, IID_IUnknown and IID_IMyInterface. The methods return E_NOINTERFACE for the first three interfaces, but return success code (S_OK) for the last two.

    The CoCreateInstance eventually return E_NOINTERFACE to the client.

    Is it because my COM component does not implement IMarshal, IStdMarshalInfo and IExternalConnection interfaces? How do add their implementation then?

  4. #4
    Join Date
    Aug 2002
    Posts
    173
    Found the cause of the problem. My proxy/stub DLL was not registered properly!

  5. #5
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    Re: CoCreateInstance returns E_NOINTERFACE

    I know this is an old post, but I am running into the exact same problem. How do you go about registering an exe properly? I have tried regsvr /r, but it doesn't seem to correct the problem. Is there an easy way to register an MFC COM executable?

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

    RegServer / UnregServer

    "If the server is packaged in an EXE module, the application wishing to register the server launches the EXE server with the command-line argument /RegServer or -RegServer (case-insensitive). If the application wishes to unregister the server, it launches the EXE with the command-line argument /UnregServer or -UnregServer." (c) MSDN

    If you have also a proxy DLL, you should register it with REGSVR32 as in-proc server.
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

  7. #7
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    Re: CoCreateInstance returns E_NOINTERFACE

    Thanks for responding - I tried this, but it doesn't seem to correct my problem. I will keep trying. I probably should start over in ATL!

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