<?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[Wie VARIANT array auswerten?]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich habe ein Problem mit dem Datentyp VARIANT, der für die Methode IWbemClassObject::Get benötigt wird.<br />
<a href="http://msdn2.microsoft.com/en-us/library/aa391442(VS.85).aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/aa391442(VS.85).aspx</a></p>
<p>Ich will jeden Wert, den diese VARIANT Variable jeweils enthält, in einen BSTR umwandeln.</p>
<pre><code class="language-cpp">//Beispiel
//so funktioniert es für Nichtarrays
HRESULT hResult;
VARIANT vVariant;

//vVariant eine int Zahl zuweisen
vVariant.intVal = 123;

//umwandeln in BSTR
hResult = VariantChangeType(&amp;vVariant, &amp;vVariant, 0, VT_BSTR);

//vVariant.bstr enthält jetzt den string &quot;123&quot;
</code></pre>
<p>Das funktioniert auch so weit einwandfrei mit VariantChangeType, nur leider nicht bei Arrays eines Typs in VARIANT. Das Steht auch so ungefähr in der MSDN: &quot;Arrays of one type cannot be converted to arrays of another type with this function.&quot;<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms221258(VS.85).aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms221258(VS.85).aspx</a></p>
<p>Ich benutze diese Methoden für WMI wo eben einige WMI Klassen auch string Arrays, uint16 Arrays, uint32 Arrays,... verwenden.</p>
<p>Mein Frage ist, ob es Funktionen gibt die mir weiter helfen könnten oder wie ich denn die Größe des jeweiligen Arrays in VARIANT raus bekommen kann?</p>
<p>Ich programmiere unter Visual Studio 2005 Pro.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/210990/wie-variant-array-auswerten</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 18:27:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/210990.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Apr 2008 14:00:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie VARIANT array auswerten? on Thu, 17 Apr 2008 14:00:06 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich habe ein Problem mit dem Datentyp VARIANT, der für die Methode IWbemClassObject::Get benötigt wird.<br />
<a href="http://msdn2.microsoft.com/en-us/library/aa391442(VS.85).aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/aa391442(VS.85).aspx</a></p>
<p>Ich will jeden Wert, den diese VARIANT Variable jeweils enthält, in einen BSTR umwandeln.</p>
<pre><code class="language-cpp">//Beispiel
//so funktioniert es für Nichtarrays
HRESULT hResult;
VARIANT vVariant;

//vVariant eine int Zahl zuweisen
vVariant.intVal = 123;

//umwandeln in BSTR
hResult = VariantChangeType(&amp;vVariant, &amp;vVariant, 0, VT_BSTR);

//vVariant.bstr enthält jetzt den string &quot;123&quot;
</code></pre>
<p>Das funktioniert auch so weit einwandfrei mit VariantChangeType, nur leider nicht bei Arrays eines Typs in VARIANT. Das Steht auch so ungefähr in der MSDN: &quot;Arrays of one type cannot be converted to arrays of another type with this function.&quot;<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms221258(VS.85).aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms221258(VS.85).aspx</a></p>
<p>Ich benutze diese Methoden für WMI wo eben einige WMI Klassen auch string Arrays, uint16 Arrays, uint32 Arrays,... verwenden.</p>
<p>Mein Frage ist, ob es Funktionen gibt die mir weiter helfen könnten oder wie ich denn die Größe des jeweiligen Arrays in VARIANT raus bekommen kann?</p>
<p>Ich programmiere unter Visual Studio 2005 Pro.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1493614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1493614</guid><dc:creator><![CDATA[oneill5000]]></dc:creator><pubDate>Thu, 17 Apr 2008 14:00:06 GMT</pubDate></item><item><title><![CDATA[Reply to Wie VARIANT array auswerten? on Sat, 19 Apr 2008 14:22:50 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-403.html" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-4.html" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1494643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1494643</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sat, 19 Apr 2008 14:22:50 GMT</pubDate></item><item><title><![CDATA[Reply to Wie VARIANT array auswerten? on Sat, 19 Apr 2008 14:34:38 GMT]]></title><description><![CDATA[<p>Du musst eben jedes Array Eleemnt konvertieren.<br />
Du hast Die Möglichkeit mit SafeArrayGetElement die Elemnte einzeln zu laden oder Du verwendest direkt SafeArrayAccessData und greifst dirket auf die Array Member zu.</p>
<p>Dir ist klar, dass dieser Array, dann auch in dem Variant verpackt ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1494649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1494649</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sat, 19 Apr 2008 14:34:38 GMT</pubDate></item><item><title><![CDATA[Reply to Wie VARIANT array auswerten? on Tue, 22 Apr 2008 14:57:58 GMT]]></title><description><![CDATA[<p>Ok vielen Dank erstmal. War auch schon etwas weiter gekommen.</p>
<p>Ja ich habe gesehen, das SAFEARRAY* und SAFEARRAY** dann auch in dem VARIANT enthalten sind.<br />
Ist natürlich etwas bescheiden schön, dass man mit VariantChangeType die Typen ändern kann, bei einem SAFEARRAY aber trotzdem wieder allein einzeln prüfen udn konvertieren muss.<br />
Ich hatte jetzt auf zum Beispiel ine BSTR Element so zugegriffen</p>
<pre><code class="language-cpp">VARIANT &amp;vVariant;
BSTR bstrString;

//vorrausgesetzt korrekte initialisierung und zuweisung des SAFEARRAY
//in vVariant
int iSize = (int)vVariant.parray-&gt;rgsabound-&gt;cElements;

for( int i = 0; i &lt; iSize; i++ )
{
	bstrString = ((BSTR*)vVariant.parray-&gt;pvData)[i];

	//bstString verarbeitende Code
	//...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1496237</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1496237</guid><dc:creator><![CDATA[oneill5000]]></dc:creator><pubDate>Tue, 22 Apr 2008 14:57:58 GMT</pubDate></item><item><title><![CDATA[Reply to Wie VARIANT array auswerten? on Tue, 22 Apr 2008 18:34:25 GMT]]></title><description><![CDATA[<p>Falsch. Das ist ein Array von Variants bei denen Du dann auf den BSTR zugreifen möchtest (sofern es einer ist, sonst ist noch ein Typechange notwendig).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1496405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1496405</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 22 Apr 2008 18:34:25 GMT</pubDate></item></channel></rss>