<?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[olefunktionen in threads verwenden - &amp;quot;coinitialize wurde nicht aufgerufen&amp;quot;]]></title><description><![CDATA[<p>hallo<br />
ich habe eine funktion mit der ich daten aus meinem programm in excel exportieren kann. funktioniert auch ganz gut, da es aber teilweise sehr viele werte sein können ist mein programm blockiert wärend des exportvorganges. jetz möchte ich die export funktion in einen thread auslagern. dabei bekomme ich aber die exeption &quot;coinitialize wurde nicht aufgerufen&quot;. soweit ich gesehen habe muss ich ole/com/dcom, oder was da auch immer zusammengehört, für jeden thread neu initialisieren. da ich mich das erste mal damit beschäftige blick ich noch nicht ganz durch. kann mir jemand zeigen wie man über einen thread auf excel zugreift?</p>
<p>so habe ich es bisher gemacht:</p>
<pre><code class="language-cpp">.h Datei:
#include &lt;comobj.hpp&gt;
#include &lt;stdio.h&gt;
Variant MyEx;
Variant MyWB;
Variant MyWS;

.cpp Datei:
// Excel starten
 MyEx = CreateOleObject(&quot;Excel.Application&quot;);
 // Excel sichtbar machen
 MyEx.OlePropertySet(&quot;Visible&quot;, true);

 // Zugriff auf die Workbooks
 MyWB = MyEx.OlePropertyGet(&quot;Workbooks&quot;);
 // Neues Workbook erstellen
 MyWB.OleFunction(&quot;Add&quot;);

 // Zugriff auf das erste Worksheet
 MyWS = MyWB.OlePropertyGet( &quot;Item&quot; , 1 );
 MyWB = MyWS.OlePropertyGet( &quot;Worksheets&quot; );

 // Dem Worksheet einen Namen geben
 MyWB.OlePropertyGet( &quot;Item&quot; , 1 ).OlePropertySet( &quot;Name&quot;, &quot;Daten&quot; );

 // Zugriff auf das erste Worksheet
 MyWS = MyWB.OlePropertyGet( &quot;Item&quot; , 1 );

 // Überschrift
 // Font nur für Zelle einstellen
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 1,1 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 1,1 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Color&quot; , clGreen );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 1,1 ).OlePropertySet( &quot;Value&quot; , &quot;Datenerfassung&quot; );

 // Überschriften
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,1 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,1 ).OlePropertySet( &quot;Value&quot; , &quot;Datum&quot; );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,2 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,2 ).OlePropertySet( &quot;Value&quot; , &quot;Uhrzeit&quot; );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,3 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,3 ).OlePropertySet( &quot;Value&quot; , &quot;Messwert&quot; );

 // Werte eintragen
 TDateTime DateAndTime;
 Randomize();

 for( int i = 5; i &lt; 15; i++ )
 {
        Sleep(500);
        DateAndTime.CurrentDateTime();
        // Datum eintragen
        MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, i,1 ).OlePropertySet( &quot;Value&quot; , DateAndTime.CurrentDate() );
        // Uhrzeit eintragen
        MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, i,2 ).OlePropertySet( &quot;Value&quot; , DateAndTime.CurrentTime() );
        // Messwert
        MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, i,3 ).OlePropertySet( &quot;Value&quot; , rand()%100 );
 }
</code></pre>
<p>euer usbfreak</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/148566/olefunktionen-in-threads-verwenden-quot-coinitialize-wurde-nicht-aufgerufen-quot</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 15:02:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/148566.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 May 2006 12:09:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to olefunktionen in threads verwenden - &amp;quot;coinitialize wurde nicht aufgerufen&amp;quot; on Sun, 28 May 2006 12:09:38 GMT]]></title><description><![CDATA[<p>hallo<br />
ich habe eine funktion mit der ich daten aus meinem programm in excel exportieren kann. funktioniert auch ganz gut, da es aber teilweise sehr viele werte sein können ist mein programm blockiert wärend des exportvorganges. jetz möchte ich die export funktion in einen thread auslagern. dabei bekomme ich aber die exeption &quot;coinitialize wurde nicht aufgerufen&quot;. soweit ich gesehen habe muss ich ole/com/dcom, oder was da auch immer zusammengehört, für jeden thread neu initialisieren. da ich mich das erste mal damit beschäftige blick ich noch nicht ganz durch. kann mir jemand zeigen wie man über einen thread auf excel zugreift?</p>
<p>so habe ich es bisher gemacht:</p>
<pre><code class="language-cpp">.h Datei:
#include &lt;comobj.hpp&gt;
#include &lt;stdio.h&gt;
Variant MyEx;
Variant MyWB;
Variant MyWS;

.cpp Datei:
// Excel starten
 MyEx = CreateOleObject(&quot;Excel.Application&quot;);
 // Excel sichtbar machen
 MyEx.OlePropertySet(&quot;Visible&quot;, true);

 // Zugriff auf die Workbooks
 MyWB = MyEx.OlePropertyGet(&quot;Workbooks&quot;);
 // Neues Workbook erstellen
 MyWB.OleFunction(&quot;Add&quot;);

 // Zugriff auf das erste Worksheet
 MyWS = MyWB.OlePropertyGet( &quot;Item&quot; , 1 );
 MyWB = MyWS.OlePropertyGet( &quot;Worksheets&quot; );

 // Dem Worksheet einen Namen geben
 MyWB.OlePropertyGet( &quot;Item&quot; , 1 ).OlePropertySet( &quot;Name&quot;, &quot;Daten&quot; );

 // Zugriff auf das erste Worksheet
 MyWS = MyWB.OlePropertyGet( &quot;Item&quot; , 1 );

 // Überschrift
 // Font nur für Zelle einstellen
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 1,1 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 1,1 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Color&quot; , clGreen );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 1,1 ).OlePropertySet( &quot;Value&quot; , &quot;Datenerfassung&quot; );

 // Überschriften
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,1 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,1 ).OlePropertySet( &quot;Value&quot; , &quot;Datum&quot; );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,2 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,2 ).OlePropertySet( &quot;Value&quot; , &quot;Uhrzeit&quot; );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,3 ).OlePropertyGet(&quot;Font&quot;).OlePropertySet( &quot;Bold&quot; , true );
 MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, 3,3 ).OlePropertySet( &quot;Value&quot; , &quot;Messwert&quot; );

 // Werte eintragen
 TDateTime DateAndTime;
 Randomize();

 for( int i = 5; i &lt; 15; i++ )
 {
        Sleep(500);
        DateAndTime.CurrentDateTime();
        // Datum eintragen
        MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, i,1 ).OlePropertySet( &quot;Value&quot; , DateAndTime.CurrentDate() );
        // Uhrzeit eintragen
        MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, i,2 ).OlePropertySet( &quot;Value&quot; , DateAndTime.CurrentTime() );
        // Messwert
        MyWS.OlePropertyGet( &quot;Cells&quot; ).OlePropertyGet( &quot;Item&quot;, i,3 ).OlePropertySet( &quot;Value&quot; , rand()%100 );
 }
</code></pre>
<p>euer usbfreak</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066585</guid><dc:creator><![CDATA[usbfreak]]></dc:creator><pubDate>Sun, 28 May 2006 12:09:38 GMT</pubDate></item><item><title><![CDATA[Reply to olefunktionen in threads verwenden - &amp;quot;coinitialize wurde nicht aufgerufen&amp;quot; on Sun, 28 May 2006 18:14:03 GMT]]></title><description><![CDATA[<p>problem gelöst!!</p>
<p>falls es noch ein paar gleichgesinnte geben sollte, hier die lösung:</p>
<p>objbase.h inkludieren und als erstes im thread die funktion CoInitialise(NULL); aufrufen.<br />
Danach kann ganz normal weitergearbeitet werden.</p>
<p>gruß usbfreak</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066902</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066902</guid><dc:creator><![CDATA[usbfreak]]></dc:creator><pubDate>Sun, 28 May 2006 18:14:03 GMT</pubDate></item></channel></rss>