<?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[Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich möchte eine Instanze einer ActiveX zur Laufzeit bilden und dann eine der Methoden dieser Componente aufrufen.<br />
Ich bin soweit, dass ich bereits eine Instanze bilde ( mit cocreateinstance(...) und createcontrol(..)). Dann hole ich mir mit GetIDsOfNames(...)<br />
die dispid der gewünschten Methode(CONFIG()). Das klappt eigentlich alles ganz gut, nur wenn ich dann die Methode zu zugehörigen dispid aufrufen möchte,<br />
bekomm ich ein HRESULT = E_UNEXPECTED.<br />
Was mach ich falsch, Danke schon einmal im Voraus.</p>
<pre><code>......

static CLSID clsid;	// i already get the right clsid from the registry

IDispatch *pInterface = 0;

CoInitialize(NULL);

// create the control 
HRESULT hRet = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void**) &amp;pInterface ); 
// examine return value 
if(hRet!=S_OK) pInterface = 0;  

CString CstrMethod = &quot;CONFIG&quot;; 
BSTR BstrMethod = CstrMethod.AllocSysString();

DISPID dispid; 

// get the id of the method									
hRet = pInterface-&gt;GetIDsOfNames(IID_NULL, &amp;BstrMethod, CLSCTX_INPROC_SERVER , LOCALE_SYSTEM_DEFAULT, &amp;dispid); 

if(hRet!=S_OK) MessageBox(&quot;It is not possible to get the Id of the method!&quot;);

CWnd m_ControlWrapper;
RECT rct = {0,0,5,50};

BOOL bStat=FALSE;
bStat= m_ControlWrapper.CreateControl(clsid, &quot;Spectrometer&quot;, WS_CHILD, rct, this, 1212, NULL, FALSE, NULL);

if (bStat == FALSE)
{
     MessageBox (&quot;Could not place control&quot;);
     return;
}

VARIANT varResult;
VariantInit(&amp;varResult);
EXCEPINFO ExceptInfo;
DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };

// here is the problem hRet = E_UNEXPECTED
hRet = pInterface-&gt;Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &amp;dispparamsNoArgs, &amp;varResult, &amp;ExceptInfo, NULL);

CoUninitialize();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/153233/problem-mit-dem-bilden-einer-instanze-einer-activex-zur-laufzeit-und-mit-dem-anschliessenden-aufrufen-einer-methode-dies</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 04:50:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/153233.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Jul 2006 10:06:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 10:29:57 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich möchte eine Instanze einer ActiveX zur Laufzeit bilden und dann eine der Methoden dieser Componente aufrufen.<br />
Ich bin soweit, dass ich bereits eine Instanze bilde ( mit cocreateinstance(...) und createcontrol(..)). Dann hole ich mir mit GetIDsOfNames(...)<br />
die dispid der gewünschten Methode(CONFIG()). Das klappt eigentlich alles ganz gut, nur wenn ich dann die Methode zu zugehörigen dispid aufrufen möchte,<br />
bekomm ich ein HRESULT = E_UNEXPECTED.<br />
Was mach ich falsch, Danke schon einmal im Voraus.</p>
<pre><code>......

static CLSID clsid;	// i already get the right clsid from the registry

IDispatch *pInterface = 0;

CoInitialize(NULL);

// create the control 
HRESULT hRet = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void**) &amp;pInterface ); 
// examine return value 
if(hRet!=S_OK) pInterface = 0;  

CString CstrMethod = &quot;CONFIG&quot;; 
BSTR BstrMethod = CstrMethod.AllocSysString();

DISPID dispid; 

// get the id of the method									
hRet = pInterface-&gt;GetIDsOfNames(IID_NULL, &amp;BstrMethod, CLSCTX_INPROC_SERVER , LOCALE_SYSTEM_DEFAULT, &amp;dispid); 

if(hRet!=S_OK) MessageBox(&quot;It is not possible to get the Id of the method!&quot;);

CWnd m_ControlWrapper;
RECT rct = {0,0,5,50};

BOOL bStat=FALSE;
bStat= m_ControlWrapper.CreateControl(clsid, &quot;Spectrometer&quot;, WS_CHILD, rct, this, 1212, NULL, FALSE, NULL);

if (bStat == FALSE)
{
     MessageBox (&quot;Could not place control&quot;);
     return;
}

VARIANT varResult;
VariantInit(&amp;varResult);
EXCEPINFO ExceptInfo;
DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };

// here is the problem hRet = E_UNEXPECTED
hRet = pInterface-&gt;Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &amp;dispparamsNoArgs, &amp;varResult, &amp;ExceptInfo, NULL);

CoUninitialize();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1097580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097580</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 10:29:57 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 10:18:44 GMT]]></title><description><![CDATA[<p>Der 3. parameter von GetIDsOfNames ist die Anzahl der Namen, das ist 1 in deinem Fall, nicht CLSCTX_INPROC_SERVER.</p>
<p>EDIT: CLSCTX_INPROC_SERVER ist 1, also ist das nicht die Ursache. Trotzdem solltest du hier nicht diese Konstante verwenden.</p>
<p>EDIT2: Bist du sicher, dass CONFIG keine Parameter braucht? Klingt irgendwie etwas seltsam...</p>
<p>EDIT3: Welche Sprache soll's denn nun sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097583</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 14 Jul 2006 10:18:44 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 10:19:32 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>CLSCTX_INPROC_SERVER ist aber als 1 definiert</p>
<p>CLSCTX_INPROC_SERVER is defined as 1</p>
<p>and</p>
<p>CONFIG() braucht keine Parameter , 100% sicher</p>
<p>CONFIG() need no Parameter ,i am sure to 100%</p>
<p>Thanks</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097587</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 10:19:32 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 10:21:49 GMT]]></title><description><![CDATA[<p>Ausserdem bekomme ich ja die richtige DISPID, ich weiss das, da mir die IDL der Componente vorliegt.</p>
<p>I know the right dispid from CONFIG() and it is the right DISPID which i get</p>
<p>Thanks</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097591</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 10:21:49 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 10:22:41 GMT]]></title><description><![CDATA[<p>masanne schrieb:</p>
<blockquote>
<p>CLSCTX_INPROC_SERVER ist aber als 1 definiert</p>
</blockquote>
<p>Mag ja sein. NUMBER_OF_GODS_IN_CHRISTIANITY ist sicher auch als 1 definiert, trotzdem würde ich es hier nicht einsetzen, weil es den Sinn nicht trifft.</p>
<p>Steht nach dem Aufruf etwas in varResult oder ExceptInfo?</p>
<p>Könntest du dich mal auf eine Sprache festlegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097592</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 14 Jul 2006 10:22:41 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 10:23:16 GMT]]></title><description><![CDATA[<p>Sprache: Dann deutsch bitte, ich habe nur den Text auch auf einer engl. Seite gepostet und erst nur kopiert.</p>
<p>sorry</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097594</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 10:23:16 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 10:31:38 GMT]]></title><description><![CDATA[<p>varresult = {VT_EMPTY} --&gt; also nichts<br />
CONFIG() hat aber eigentlich auch keinen Rückgabewert , es soll sich nur eine Dialog Box öffnen</p>
<p>ExceptInfo = {wCode=52428 wReserved=52428 bstrSource=0xcccccccc &lt;Bad Ptr&gt; ...}<br />
das sagt mir aber nichts, ich denke das es leer ist, da vor dem Aufruf von invoke die gleichen Informationen für ExceptInfo da stehen ( im Debug-Modus)</p>
<p>masanne</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097600</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 10:31:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 11:15:33 GMT]]></title><description><![CDATA[<p>Keine Plan mehr, was noch falsch sein könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097622</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 11:15:33 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 11:19:38 GMT]]></title><description><![CDATA[<p>Ich vermute, du erzeugst zwei Objekte, und rufst Invoke mit dem falschen auf. Vielleicht kann jemand dazu etwas sagen, der sich besser mit der Verwendung von ActiveX-Controls ohne Wrapper auskennt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097624</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 14 Jul 2006 11:19:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 11:25:00 GMT]]></title><description><![CDATA[<p>wie kommst du darauf, dass ich zwei Instanzen erzeuge? wegen cocreateinstance und createcontrol?</p>
<p>Trotzdem schonmal Danke das du dir Zeit genommen hast</p>
<p>masanne</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097631</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 11:25:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 11:26:51 GMT]]></title><description><![CDATA[<p>masanne schrieb:</p>
<blockquote>
<p>wie kommst du darauf, dass ich zwei Instanzen erzeuge? wegen cocreateinstance und createcontrol?</p>
</blockquote>
<p>Genau. Ich vermute, letzteres erzeugt auch eine Instanz des Steuerelements. Und vermutlich kann nur die richig auf CONFIG reagieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097635</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 14 Jul 2006 11:26:51 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit dem Bilden einer Instanze einer ActiveX zur Laufzeit und mit dem anschliessenden Aufrufen einer Methode dies on Fri, 14 Jul 2006 12:53:56 GMT]]></title><description><![CDATA[<p>MFK schrieb:</p>
<blockquote>
<p>masanne schrieb:</p>
<blockquote>
<p>wie kommst du darauf, dass ich zwei Instanzen erzeuge? wegen cocreateinstance und createcontrol?</p>
</blockquote>
<p>Genau. Ich vermute, letzteres erzeugt auch eine Instanz des Steuerelements. Und vermutlich kann nur die richig auf CONFIG reagieren.</p>
</blockquote>
<p>Das war der entscheidende Satz. Danke Schön.</p>
<pre><code>...
CoInitialize(NULL);

CWnd m_ControlWrapper;
RECT rct = {0,0,5,50};

BOOL bStat=FALSE;
bStat= m_ControlWrapper.CreateControl(clsid, &quot;Spectrometer&quot;, WS_CHILD, rct, this, 1212, NULL, FALSE, NULL);

if (bStat == FALSE)
{
	MessageBox (&quot;Could not place control&quot;);
	return;
}

// Use the IUnknown of the control.
LPUNKNOWN pUnk = m_ControlWrapper.GetControlUnknown();

// From there get the IDispatch interface of control.
LPDISPATCH pInterface = NULL;
pUnk-&gt;QueryInterface(IID_IDispatch, (LPVOID*)&amp;pInterface);

CString CstrMethod = &quot;CONFIG&quot;; // andere Methode z.B. &quot;SCAN&quot;
BSTR BstrMethod = CstrMethod.AllocSysString();

DISPID dispid; 

// get the id of the method									
HRESULT hRet = pInterface-&gt;GetIDsOfNames(IID_NULL, &amp;BstrMethod, CLSCTX_INPROC_SERVER , LOCALE_SYSTEM_DEFAULT, &amp;dispid); 

m_ControlWrapper.InvokeHelper(dispid, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);//InvokeHelper(0xc, DISPATCH_METHOD , VT_EMPTY, NULL, NULL);

CoUninitialize(); 
...
</code></pre>
<p>Nur, dass ich das CONFIG-Window nicht angezeigt bekomm. Aber wenn ich es mit einer anderen Methode versuche, klappt es.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097697</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097697</guid><dc:creator><![CDATA[masanne]]></dc:creator><pubDate>Fri, 14 Jul 2006 12:53:56 GMT</pubDate></item></channel></rss>