<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[HILFE, Beim Aufruf der COM Methode stürzt das Programm ab...]]></title><description><![CDATA[<p>Hallo Leute, ich habe im Moment ein Problem mit einer COM Klasse. (SphinxIO)<br />
Was habe ich gemacht:<br />
Über den OleViewer habe ich mir alle Schnittstellen definitionen angeguckt:</p>
<pre><code class="language-cpp">// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: SphComIO.dll

[
  uuid(A11CAE80-89AC-11D6-9A75-0050042E6E58),
  version(5.3),
  helpstring(&quot;SphComIO 5.0.0.3 Type Library&quot;),
  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(&quot;stdole2.tlb&quot;);

    // Forward declare all types defined in this typelib
    interface Isphio;
    interface ISphiom;

    [
      uuid(A11CAE8E-89AC-11D6-9A75-0050042E6E58),
      helpstring(&quot;sphio Class&quot;)
    ]
    coclass sphio {
        [default] interface Isphio;
    };

    [
      odl,
      uuid(A11CAE8D-89AC-11D6-9A75-0050042E6E58),
      helpstring(&quot;Isphio Interface&quot;),
      dual,
      oleautomation
    ]
    interface Isphio : IDispatch {
        [id(0x60020000)]
        HRESULT OnStartPage([in] IUnknown* piUnk);
        [id(0x60020001)]
        HRESULT OnEndPage();
        [id(0x00000001), helpstring(&quot;method SphinxCreerEnquete&quot;)]
        HRESULT SphinxCreerEnquete(
                        [in] BSTR enquete, 
                        [out, retval] int* pVal);
        [id(0x00000002), helpstring(&quot;method SphinxOuvrirEnquete&quot;)]
        HRESULT SphinxOuvrirEnquete(
                        [in] BSTR enquete, 
                        [out, retval] int* pVal);
        [id(0x00000003), helpstring(&quot;method SphinxFermerEnquete&quot;)]
        HRESULT SphinxFermerEnquete([out, retval] int* pVal);
.....
</code></pre>
<p><strong>Daraus habe ich mir dann eine Header Datei gebastelt:</strong></p>
<pre><code class="language-cpp">#include &lt;initguid.h&gt;

//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;
...
</code></pre>
<p><strong>So und dann habe versucht das ganze zu benutzen:</strong></p>
<pre><code class="language-cpp">if(FAILED(CoInitialize(NULL)))
	{
		AfxMessageBox(&quot;Failed to init COM&quot;);
		return;
	}
	CLSID clsid;
	CLSIDFromString(L&quot;{A11CAE8E-89AC-11D6-9A75-0050042E6E58}&quot;, &amp;clsid);

	Isphio *isphio = NULL;
	IClassFactory *factory = NULL;
	if(FAILED(CoGetClassObject(clsid, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&amp;factory)))
	{
		AfxMessageBox(&quot;Failed to get the class factory&quot;);
		return;
	}
	if(FAILED(factory-&gt;CreateInstance(NULL, IID_Isphio, (void**)&amp;isphio)))
	{
		AfxMessageBox(&quot;Failed to init Object through Factory Class&quot;);
		return;
	}

	/*if(FAILED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_Isphio, (void**)&amp;isphio)))
	{
		AfxMessageBox(&quot;Failed to create Instance of COM Object&quot;);
		return;
	}*/
	if(!isphio)
	{
		AfxMessageBox(&quot;Kein Objekt!&quot;);
		return;
	}

	int *retVal = NULL;
	BSTR surveyName = SysAllocString(L&quot;Gerda&quot;);
	if(FAILED(isphio-&gt;SphinxCreerEnquete(surveyName, retVal)))
	{
		AfxMessageBox(&quot;Failed to call SphinxCreerEnquete(...)&quot;);
		return;
	}
	else
	{
		CString str;
		str.Format(&quot;Return Value: %n&quot;, retVal);
		AfxMessageBox(str);
	}
	SysFreeString(surveyName);
	isphio-&gt;Release();
	CoUninitialize();
</code></pre>
<p>Allerdings stürzt das Programm beim Aufruf der Sphinx Methode ab...</p>
<p>Kann mir da jemand weiter helfen? Wäre wirklich wichtig!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/91700/hilfe-beim-aufruf-der-com-methode-stürzt-das-programm-ab</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 12:00:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/91700.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Nov 2004 12:12:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to HILFE, Beim Aufruf der COM Methode stürzt das Programm ab... on Thu, 11 Nov 2004 12:12:17 GMT]]></title><description><![CDATA[<p>Hallo Leute, ich habe im Moment ein Problem mit einer COM Klasse. (SphinxIO)<br />
Was habe ich gemacht:<br />
Über den OleViewer habe ich mir alle Schnittstellen definitionen angeguckt:</p>
<pre><code class="language-cpp">// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: SphComIO.dll

[
  uuid(A11CAE80-89AC-11D6-9A75-0050042E6E58),
  version(5.3),
  helpstring(&quot;SphComIO 5.0.0.3 Type Library&quot;),
  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(&quot;stdole2.tlb&quot;);

    // Forward declare all types defined in this typelib
    interface Isphio;
    interface ISphiom;

    [
      uuid(A11CAE8E-89AC-11D6-9A75-0050042E6E58),
      helpstring(&quot;sphio Class&quot;)
    ]
    coclass sphio {
        [default] interface Isphio;
    };

    [
      odl,
      uuid(A11CAE8D-89AC-11D6-9A75-0050042E6E58),
      helpstring(&quot;Isphio Interface&quot;),
      dual,
      oleautomation
    ]
    interface Isphio : IDispatch {
        [id(0x60020000)]
        HRESULT OnStartPage([in] IUnknown* piUnk);
        [id(0x60020001)]
        HRESULT OnEndPage();
        [id(0x00000001), helpstring(&quot;method SphinxCreerEnquete&quot;)]
        HRESULT SphinxCreerEnquete(
                        [in] BSTR enquete, 
                        [out, retval] int* pVal);
        [id(0x00000002), helpstring(&quot;method SphinxOuvrirEnquete&quot;)]
        HRESULT SphinxOuvrirEnquete(
                        [in] BSTR enquete, 
                        [out, retval] int* pVal);
        [id(0x00000003), helpstring(&quot;method SphinxFermerEnquete&quot;)]
        HRESULT SphinxFermerEnquete([out, retval] int* pVal);
.....
</code></pre>
<p><strong>Daraus habe ich mir dann eine Header Datei gebastelt:</strong></p>
<pre><code class="language-cpp">#include &lt;initguid.h&gt;

//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;
...
</code></pre>
<p><strong>So und dann habe versucht das ganze zu benutzen:</strong></p>
<pre><code class="language-cpp">if(FAILED(CoInitialize(NULL)))
	{
		AfxMessageBox(&quot;Failed to init COM&quot;);
		return;
	}
	CLSID clsid;
	CLSIDFromString(L&quot;{A11CAE8E-89AC-11D6-9A75-0050042E6E58}&quot;, &amp;clsid);

	Isphio *isphio = NULL;
	IClassFactory *factory = NULL;
	if(FAILED(CoGetClassObject(clsid, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&amp;factory)))
	{
		AfxMessageBox(&quot;Failed to get the class factory&quot;);
		return;
	}
	if(FAILED(factory-&gt;CreateInstance(NULL, IID_Isphio, (void**)&amp;isphio)))
	{
		AfxMessageBox(&quot;Failed to init Object through Factory Class&quot;);
		return;
	}

	/*if(FAILED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_Isphio, (void**)&amp;isphio)))
	{
		AfxMessageBox(&quot;Failed to create Instance of COM Object&quot;);
		return;
	}*/
	if(!isphio)
	{
		AfxMessageBox(&quot;Kein Objekt!&quot;);
		return;
	}

	int *retVal = NULL;
	BSTR surveyName = SysAllocString(L&quot;Gerda&quot;);
	if(FAILED(isphio-&gt;SphinxCreerEnquete(surveyName, retVal)))
	{
		AfxMessageBox(&quot;Failed to call SphinxCreerEnquete(...)&quot;);
		return;
	}
	else
	{
		CString str;
		str.Format(&quot;Return Value: %n&quot;, retVal);
		AfxMessageBox(str);
	}
	SysFreeString(surveyName);
	isphio-&gt;Release();
	CoUninitialize();
</code></pre>
<p>Allerdings stürzt das Programm beim Aufruf der Sphinx Methode ab...</p>
<p>Kann mir da jemand weiter helfen? Wäre wirklich wichtig!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/649356</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/649356</guid><dc:creator><![CDATA[Win32Noob]]></dc:creator><pubDate>Thu, 11 Nov 2004 12:12:17 GMT</pubDate></item></channel></rss>