+ Reply to Thread
Results 1 to 2 of 2

Thread: CoCreateInstance always returns -2147024809 error code. Why?

  1. #1

    CoCreateInstance always returns -2147024809 error code. Why?

    I have following program. I want to create an instance of COM object.

    But CoCreateInstance returns -2147024809 code always.

    Code:
    void UseCOM()
    {
           CoInitialize(NULL) ;
    
    	IMyInterface* pMyInterface = NULL ;
    
    	HRESULT hr = CoCreateInstance(__uuidof(MyClass), NULL, CLSCTX_INPROC_SERVER,__uuidof(MyInterface), (LPVOID *) pMyInterface) ;
    
    	if (NULL != pMyInterface)
    	{
    		long data ;
    		pMyInterface->GetValue(&data) ;
    	}
    }
    What could be the reason?

  2. #2
    Error code means : "The parameter is incorrect"

    Use "(LPVOID *) &pMyInterface" as last parameter. Note the "&".

    Code:
    void UseCOM()
    {
           CoInitialize(NULL) ;
    
    	IMyInterface* pMyInterface = NULL ;
    
    	HRESULT hr = CoCreateInstance(__uuidof(MyClass), NULL, CLSCTX_INPROC_SERVER,__uuidof(MyInterface), (LPVOID *) &pMyInterface) ;
    
    	if (NULL != pMyInterface)
    	{
    		long data ;
    		pMyInterface->GetValue(&data) ;
    	}
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts