|
-
April 2nd, 2012, 03:00 PM
#1
Using _bstr_t and _variant_t in a C++ application
Hi there,
I'm very new to COM programming, so my apologies in advance for the basic question. I've written a code in C++ that uses COM to access another application from out-of-process. This generally works well, but occasionally (20-30% of the time) my code causes a "crash" of the other application. I've determined the part of the code that is failing, but cannot figure out why.
Basically what I'm trying to do is obtain some information from the application that I'm calling out-of-process. This information is stored as _bstr_t and _variant_t data in smart pointers. Here is the basics of how I'm getting at the data:
Code:
CComPtr<Document> MyDoc;
CComQIPtr<Part> MyPart(MyDoc);
int ii, ndim;
double dvalue;
_bstr_t bsName;
_variant_t tempValue;
ndim = MyDoc->Count;
for (ii = 1; ii <= ndim; ii++)
{
bsName = MyPart->Name;
tempValue = MyPart->Value;
if (tempValue.vt == VT_R8) dvalue = tempValue.dblVal;
else dvalue = 0.0;
}
MyPart.Release();
MyDoc.Release();
I'm not doing anything to "release" or "free" the _bstr_t or _variant_t variables, but my understanding is that I don't have to. But is this the potential problem? Or is there anything else that I might be doing wrong?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|