Click here to Skip to main content
15,891,856 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Hi,
I am trying to open a com objekt and CoCreateInstance give me an error (E_NOINTERFACE). This is my first time using COM objects.

C++
bool registerASIOCOM()
{
    HRESULT err;
    CLSID clsidASIO;
    IID iidASIO;
    IASIO* pIAD;
    
    wchar_t clsidStr[MAX_VALUE_DATA];

    if(!getASIODriverCLSIDs(clsidStr)) //custom method to get CLSID from the registry (HKCM\SOFTWARE\ASIO)
        return 0;

    err = CLSIDFromString(clsidStr, &clsidASIO);

    if(err != S_OK)
    {
        return false;
    }

    err = IIDFromString(clsidStr, &iidASIO); // iid is the same as clsid

    if(err != S_OK)
    {
        return false;
    }

    err = CoInitializeEx(NULL, COINIT_SPEED_OVER_MEMORY);

    if(err != S_OK)
    {
        return false;
    }
    
    
    err = CoCreateInstance ( clsidASIO, NULL, CLSCTX_INPROC_SERVER,
                             iidASIO, (void**) &pIAD );
    if(err != S_OK)
    {
        printf("%x", err); //errorcode 80004002
        return 0;
    }

    return true;
}



IASIO is as following:

C++
interface IASIO : public IUnknown

{

        virtual ASIOBool init(HWND sysHandle) = 0;

        virtual void getDriverName(char *name) = 0;

        virtual long getDriverVersion() = 0;

        virtual void getErrorMessage(char *string) = 0;

        virtual ASIOError start() = 0;

        virtual ASIOError stop() = 0;

        virtual ASIOError getChannels(long *numInputChannels, long *numOutputChannels) = 0;

        virtual ASIOError getLatencies(long *inputLatency, long *outputLatency) = 0;

        virtual ASIOError getBufferSize(long *minSize, long *maxSize,

                long *preferredSize, long *granularity) = 0;

        virtual ASIOError canSampleRate(ASIOSampleRate sampleRate) = 0;

        virtual ASIOError getSampleRate(ASIOSampleRate *sampleRate) = 0;

        virtual ASIOError setSampleRate(ASIOSampleRate sampleRate) = 0;

        virtual ASIOError getClockSources(ASIOClockSource *clocks, long *numSources) = 0;

        virtual ASIOError setClockSource(long reference) = 0;

        virtual ASIOError getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp) = 0;

        virtual ASIOError getChannelInfo(ASIOChannelInfo *info) = 0;

        virtual ASIOError createBuffers(ASIOBufferInfo *bufferInfos, long numChannels,

                long bufferSize, ASIOCallbacks *callbacks) = 0;

        virtual ASIOError disposeBuffers() = 0;

        virtual ASIOError controlPanel() = 0;

        virtual ASIOError future(long selector,void *opt) = 0;

        virtual ASIOError outputReady() = 0;

};
Posted
Comments
Marius Bancila 25-Sep-12 16:21pm    
Did you debug? What are the values of clsidStr, clsidASIO and iidASIO? Do they hold what you expect? What kind of app is this? 32 or 64-bit? And what target machine is it? x86 or x64? Notice that if this is for instance a 64-bit app and the COM server is registered in the 32-bit view of the registry, than the app cannot read the COM registry data. Nor the other way around (a 32-bit app and a COM server registered in the native 64-bit registry view).
daniel3891 26-Sep-12 4:24am    
Found the bug: simply add COINIT_APARTMENTTHREADED to CoInitializeEx and it works.

Found the bug: simply add COINIT_APARTMENTTHREADED to CoInitializeEx and it works.
 
Share this answer
 
Try to debug methods CreateInstance and QueryInterface of your COM object. E_NOINTERFACE means some interface is not supported
 
Share this answer
 
Hello,

You writing that IID is the same as CLSID that probably an error.

1. Be sure that the CLSID and IID are the same as in IDL file.
If you have no IDL file try to load the COM DLL in there object located in OLE View Tool via menu: File->View TypeLib. in there you can find the CLSID and IID of your object.
> NOTE: Type Library can be in separate file with same name but with *.tlb extension.
> NOTE: Worst if COM DLL does not contain Type Library in that case try to find CLSID in registry: HKCR\CLSID\{"Your CLSID"} - it should exists and subkey "InprocServer32" should consist of path to your DLL.
2. Try to initialize your object with IUnknown interface and query your interface from it - this way you will find there an issue in IID or CLSID:
C++
IUnknown * pUnknown;
HRESULT hr;
hr = CoCreateInstance (clsidASIO, NULL, CLSCTX_INPROC_SERVER,
                            IID_IUnknown, (void**) &pUnknown );
// if succeeded hr your CLSID exists you can query interface
hr = pUnknown-<QueryInterface(iidASIO, (void**) &pIAD);
// if succeeded hr you got your interface object otherwise you specify wrong iid
.....
// dont forget release initial unknown
pUnknown-<Release();


Regards,
Maxim.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900