<?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[COM - using BSTR]]></title><description><![CDATA[<p>Hi</p>
<ol>
<li>
<p>Situation<br />
============<br />
My task is to write a program in VC++ which makes a windows program communicate to a sensor (MTi). There is a fully functional command line program from the producer of the sensor. Now i want to change severel settings (using specific functions) of the sensor like sample frequency and so on. The main function makes a Motion Tracker Object (written in c) to realize the communication through a virtual COM Port.</p>
</li>
<li>
<p>Problem<br />
==========<br />
I want to change the sample frequency of the data exchange between the program and the sensor (default it is 100Hz which is to fast for my application):</p>
</li>
</ol>
<p>&lt;code&gt;<br />
int nSFreq=25; //Sample Frequency in Hz<br />
int nUSFreq=0; //Used sample Frequency<br />
//Set new sample Frequency where pMT is the created Motion Tracker Object<br />
pMT-&gt;MT_SetMotionTrackerSampleFrequency(nSFreq);<br />
//Show the Sample Frequency for checkup<br />
MT_GetMotionTrackerSampleFrequency(&amp;nUSFreq);<br />
//Show it on command Line<br />
printf(&quot;Your sample Frequency %d&quot;, nUSFreq);<br />
&lt;/code&gt;</p>
<p>--&gt; the command line shows 25 as expected, but the sensor samples still with 100Hz. Now i read that i have to safe the settings on the sensor using the sensor ID which is a BSTR. The ID i can get from this function:</p>
<p>&lt;code&gt;<br />
//get the device ID<br />
virtual HRESULT STDMETHODCALLTYPE MT_QueryMotionTrackerB(<br />
/* [out] */ BSTR __RPC_FAR *bstrDeviceID) = 0;<br />
//safe the new settings trough this function<br />
virtual HRESULT STDMETHODCALLTYPE MT_SaveToMTS(<br />
BSTR bstrDeviceID) = 0;<br />
&lt;/code&gt;</p>
<p>--&gt; now, what i have done in my program:</p>
<p>&lt;code&gt;<br />
BSTR nDId;<br />
//get the Device ID<br />
pMT-&gt;MT_QueryMotionTrackerB(&amp;nDId);<br />
//safe settings<br />
pMT-&gt;MT_SaveToMTS(nDId);<br />
&lt;/code&gt;</p>
<p>--&gt;The program compiles very nice but when i run the .exe i got this damn error message all the time:<br />
&quot;An exception 'System.NullRefereceException' has occured in MTi.cmd1.exe&quot;<br />
(--&gt;The error is only caused when i use the BSTR function shown above)</p>
<p>I know the problem is this BSTR but i cant help myself. Maybe someone can tell me what i need to do.<br />
1000Thx</p>
<p>chris</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/168014/com-using-bstr</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 04:25:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/168014.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 Dec 2006 15:53:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to COM - using BSTR on Sun, 17 Dec 2006 15:53:51 GMT]]></title><description><![CDATA[<p>Hi</p>
<ol>
<li>
<p>Situation<br />
============<br />
My task is to write a program in VC++ which makes a windows program communicate to a sensor (MTi). There is a fully functional command line program from the producer of the sensor. Now i want to change severel settings (using specific functions) of the sensor like sample frequency and so on. The main function makes a Motion Tracker Object (written in c) to realize the communication through a virtual COM Port.</p>
</li>
<li>
<p>Problem<br />
==========<br />
I want to change the sample frequency of the data exchange between the program and the sensor (default it is 100Hz which is to fast for my application):</p>
</li>
</ol>
<p>&lt;code&gt;<br />
int nSFreq=25; //Sample Frequency in Hz<br />
int nUSFreq=0; //Used sample Frequency<br />
//Set new sample Frequency where pMT is the created Motion Tracker Object<br />
pMT-&gt;MT_SetMotionTrackerSampleFrequency(nSFreq);<br />
//Show the Sample Frequency for checkup<br />
MT_GetMotionTrackerSampleFrequency(&amp;nUSFreq);<br />
//Show it on command Line<br />
printf(&quot;Your sample Frequency %d&quot;, nUSFreq);<br />
&lt;/code&gt;</p>
<p>--&gt; the command line shows 25 as expected, but the sensor samples still with 100Hz. Now i read that i have to safe the settings on the sensor using the sensor ID which is a BSTR. The ID i can get from this function:</p>
<p>&lt;code&gt;<br />
//get the device ID<br />
virtual HRESULT STDMETHODCALLTYPE MT_QueryMotionTrackerB(<br />
/* [out] */ BSTR __RPC_FAR *bstrDeviceID) = 0;<br />
//safe the new settings trough this function<br />
virtual HRESULT STDMETHODCALLTYPE MT_SaveToMTS(<br />
BSTR bstrDeviceID) = 0;<br />
&lt;/code&gt;</p>
<p>--&gt; now, what i have done in my program:</p>
<p>&lt;code&gt;<br />
BSTR nDId;<br />
//get the Device ID<br />
pMT-&gt;MT_QueryMotionTrackerB(&amp;nDId);<br />
//safe settings<br />
pMT-&gt;MT_SaveToMTS(nDId);<br />
&lt;/code&gt;</p>
<p>--&gt;The program compiles very nice but when i run the .exe i got this damn error message all the time:<br />
&quot;An exception 'System.NullRefereceException' has occured in MTi.cmd1.exe&quot;<br />
(--&gt;The error is only caused when i use the BSTR function shown above)</p>
<p>I know the problem is this BSTR but i cant help myself. Maybe someone can tell me what i need to do.<br />
1000Thx</p>
<p>chris</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193527</guid><dc:creator><![CDATA[chris001z]]></dc:creator><pubDate>Sun, 17 Dec 2006 15:53:51 GMT</pubDate></item><item><title><![CDATA[Reply to COM - using BSTR on Sun, 17 Dec 2006 16:28:35 GMT]]></title><description><![CDATA[<p>First: This is a german fourm.<br />
Second: A BSTR is a special wchar_t string. When you want to use it you need to allocate one with SysAllocString. Also you can use CComBSTR.<br />
Third: You haven't shown all the interface functions you want to use. Also is MT_QueryMotionTrackerB a standard COM interface function. In this case it depends is MT_QueryMotionTrackerB is declared as in/out or only as out. If it is declared as in/out you have to pass a valid BSTR into the function. If declared only as out I wonder about the error.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193555</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 17 Dec 2006 16:28:35 GMT</pubDate></item><item><title><![CDATA[Reply to COM - using BSTR on Tue, 19 Dec 2006 13:59:26 GMT]]></title><description><![CDATA[<p>Zu 1) Dann schreibe ich Deutsch, wenn das Englisch nicht geläufig ist.</p>
<p>Zu 2) Glaube ich nicht, ich möchte den BSTR ja nicht weiter verwenden, sondern direkt wieder an das COM Objekt übergeben.</p>
<p>Zu 3) Die Funktionen sind wie folgt deklariert. Ich nehme an, es handelt sich um einen reinen out, wie es im Kommentar vermerkt ist. Ich habe das COM Objekt nicht selbst programmiert.</p>
<p>&lt;code&gt;<br />
//get the device ID<br />
virtual HRESULT STDMETHODCALLTYPE MT_QueryMotionTrackerB(<br />
/* [out] */ BSTR __RPC_FAR *bstrDeviceID) = 0;<br />
//safe the new settings trough this function<br />
virtual HRESULT STDMETHODCALLTYPE MT_SaveToMTS(<br />
BSTR bstrDeviceID) = 0;<br />
&lt;/code&gt;</p>
<p>Zum letzten Satz) Ich kriege tatsächlich keine Error Meldung mehr. Was aber noch viel schlimmer ist, weil er etwas compiled aber nicht korrekt ausführt.</p>
<p>Ich Versuchs weiter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1194815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1194815</guid><dc:creator><![CDATA[chris001z]]></dc:creator><pubDate>Tue, 19 Dec 2006 13:59:26 GMT</pubDate></item><item><title><![CDATA[Reply to COM - using BSTR on Wed, 20 Dec 2006 07:41:42 GMT]]></title><description><![CDATA[<p>chris001z schrieb:</p>
<blockquote>
<p>Zu 1) Dann schreibe ich Deutsch, wenn das Englisch nicht geläufig ist.</p>
</blockquote>
<p>Was heißt nicht geläufig. Englische Gruppen kannst Du gerne besuchen und dort dann Deutsch schreiben. Viel Spass beim warten auf Antworten.<br />
Dies ist eine Deutsche Gruppe, also warum nicht Deutsch schreiben?</p>
<p>chris001z schrieb:</p>
<blockquote>
<p>Zu 2) Glaube ich nicht, ich möchte den BSTR ja nicht weiter verwenden, sondern direkt wieder an das COM Objekt übergeben.</p>
</blockquote>
<p>Wenn die Funktion orndungsgemäß funktionieren würde und den BSTR als out übergibt, dann müsste dieser auch gefüllt werden.<br />
Du müsstest ihn auch selbst anschließend entsorgen.</p>
<p>chris001z schrieb:</p>
<blockquote>
<p>Zu 3) Die Funktionen sind wie folgt deklariert. Ich nehme an, es handelt sich um einen reinen out, wie es im Kommentar vermerkt ist. Ich habe das COM Objekt nicht selbst programmiert.</p>
<p>&lt;code&gt;<br />
//get the device ID<br />
virtual HRESULT STDMETHODCALLTYPE MT_QueryMotionTrackerB(<br />
/* [out] */ BSTR __RPC_FAR *bstrDeviceID) = 0;<br />
//safe the new settings trough this function<br />
virtual HRESULT STDMETHODCALLTYPE MT_SaveToMTS(<br />
BSTR bstrDeviceID) = 0;<br />
&lt;/code&gt;</p>
</blockquote>
<p>In diesem Fall müsstest Du nur einen Zeiger auf einen BSTR übergeben. Das wars</p>
<p>chris001z schrieb:</p>
<blockquote>
<p>BSTR myStr=NULL;<br />
pInterface-&gt;MT_QueryMotionTrackerB(&amp;myStr);</p>
</blockquote>
<p>Der Init mit NULL wäre nicht nötig, aber ist manchmal angebracht, wenn der COM Programmierer out und in/out verwechselt hat.</p>
<p>Anschließend musst Du das gute Stück freigeben. Das würde sich erübrigen bei Verwendung eines CComBSTR!</p>
<p>chris001z schrieb:</p>
<blockquote>
<p>Zum letzten Satz) Ich kriege tatsächlich keine Error Meldung mehr. Was aber noch viel schlimmer ist, weil er etwas compiled aber nicht korrekt ausführt.</p>
</blockquote>
<p>Tja... Entwickler kontaktieren...<br />
:xmas2:<br />
Ich Versuchs weiter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195214</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 20 Dec 2006 07:41:42 GMT</pubDate></item></channel></rss>