HILFE, Beim Aufruf der COM Methode stürzt das Programm ab...



  • Hallo Leute, ich habe im Moment ein Problem mit einer COM Klasse. (SphinxIO)
    Was habe ich gemacht:
    Über den OleViewer habe ich mir alle Schnittstellen definitionen angeguckt:

    // Generated .IDL file (by the OLE/COM Object Viewer)
    // 
    // typelib filename: SphComIO.dll
    
    [
      uuid(A11CAE80-89AC-11D6-9A75-0050042E6E58),
      version(5.3),
      helpstring("SphComIO 5.0.0.3 Type Library"),
      custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 83951780),
      custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1068625984)
    
    ]
    library SPHCOMIOLib
    {
        // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
        importlib("stdole2.tlb");
    
        // Forward declare all types defined in this typelib
        interface Isphio;
        interface ISphiom;
    
        [
          uuid(A11CAE8E-89AC-11D6-9A75-0050042E6E58),
          helpstring("sphio Class")
        ]
        coclass sphio {
            [default] interface Isphio;
        };
    
        [
          odl,
          uuid(A11CAE8D-89AC-11D6-9A75-0050042E6E58),
          helpstring("Isphio Interface"),
          dual,
          oleautomation
        ]
        interface Isphio : IDispatch {
            [id(0x60020000)]
            HRESULT OnStartPage([in] IUnknown* piUnk);
            [id(0x60020001)]
            HRESULT OnEndPage();
            [id(0x00000001), helpstring("method SphinxCreerEnquete")]
            HRESULT SphinxCreerEnquete(
                            [in] BSTR enquete, 
                            [out, retval] int* pVal);
            [id(0x00000002), helpstring("method SphinxOuvrirEnquete")]
            HRESULT SphinxOuvrirEnquete(
                            [in] BSTR enquete, 
                            [out, retval] int* pVal);
            [id(0x00000003), helpstring("method SphinxFermerEnquete")]
            HRESULT SphinxFermerEnquete([out, retval] int* pVal);
    .....
    

    Daraus habe ich mir dann eine Header Datei gebastelt:

    #include <initguid.h>
    
    //A11CAE8D-89AC-11D6-9A75-0050042E6E58
    DEFINE_GUID(IID_Isphio, 0xA11CAE8D, 0x89AC, 0x11D6, 0x9A, 0x75, 0x00, 0x50, 0x04, 0x2E, 0x6E, 0x58);
    
    #undef INTERFACE
    #define INTERFACE Isphio
    DECLARE_INTERFACE_(Isphio, IDispatch)
    {
    	STDMETHOD(QueryInterface) (THIS_ REFIID riid, PVOID* ppvObj)PURE; 
    	//same as: virtual STDMETHOD(__stdcall QueryInterface(REFIID riid, void** ppvObj)=0;
        STDMETHOD_(ULONG, AddRef) (THIS)PURE; 
        STDMETHOD_(ULONG, Release)(THIS)PURE; //same as: virtual ULONG __stdcall Release(void) = 0;
    
    	STDMETHOD(GetTypeInfoCount)(THIS_ UINT* pctinfo)PURE; 
        STDMETHOD(GetTypeInfo)(THIS_ UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)PURE; 
        STDMETHOD(GetIDsOfNames)(THIS_ REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)PURE; 
        STDMETHOD(Invoke)(THIS_ DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)PURE;
    
    	STDMETHOD(SphinxCreerEnquete) (BSTR enquete, int* pVal)PURE;
    	STDMETHOD(SphinxOuvrirEnquete) (BSTR enquete, int* pVal)PURE;
        STDMETHOD(SphinxFermerEnquete) (int* pVal)PURE;
    ...
    

    So und dann habe versucht das ganze zu benutzen:

    if(FAILED(CoInitialize(NULL)))
    	{
    		AfxMessageBox("Failed to init COM");
    		return;
    	}
    	CLSID clsid;
    	CLSIDFromString(L"{A11CAE8E-89AC-11D6-9A75-0050042E6E58}", &clsid);
    
    	Isphio *isphio = NULL;
    	IClassFactory *factory = NULL;
    	if(FAILED(CoGetClassObject(clsid, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&factory)))
    	{
    		AfxMessageBox("Failed to get the class factory");
    		return;
    	}
    	if(FAILED(factory->CreateInstance(NULL, IID_Isphio, (void**)&isphio)))
    	{
    		AfxMessageBox("Failed to init Object through Factory Class");
    		return;
    	}
    
    	/*if(FAILED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_Isphio, (void**)&isphio)))
    	{
    		AfxMessageBox("Failed to create Instance of COM Object");
    		return;
    	}*/
    	if(!isphio)
    	{
    		AfxMessageBox("Kein Objekt!");
    		return;
    	}
    
    	int *retVal = NULL;
    	BSTR surveyName = SysAllocString(L"Gerda");
    	if(FAILED(isphio->SphinxCreerEnquete(surveyName, retVal)))
    	{
    		AfxMessageBox("Failed to call SphinxCreerEnquete(...)");
    		return;
    	}
    	else
    	{
    		CString str;
    		str.Format("Return Value: %n", retVal);
    		AfxMessageBox(str);
    	}
    	SysFreeString(surveyName);
    	isphio->Release();
    	CoUninitialize();
    

    Allerdings stürzt das Programm beim Aufruf der Sphinx Methode ab...

    Kann mir da jemand weiter helfen? Wäre wirklich wichtig!

    Gruß


Anmelden zum Antworten