Article View: borland.public.cppbuilder.nativeapi
Article #800Re: WMI Network unplugged
From: Remy Lebeau (TeamB)
Date: Mon, 14 Jan 2008 18:05
Date: Mon, 14 Jan 2008 18:05
73 lines
3210 bytes
3210 bytes
"JohnG" <whatis@email.com> wrote in message
news:478b8203$1@newsgroups.borland.com...
> hr = locator->ConnectServer( L"root\\cimv2", NULL, NULL, NULL,
> WBEM_FLAG_CONNECT_USE_MAX_WAIT,
> NULL, NULL, &service );
You must use a true BSTR, not a raw wchar_t*, when passing strings to COM
objects. You can use the VCL's WideString class to help you with that, ie:
hr = locator->ConnectServer(WideString("root\\cimv2"), ...);
> hr = service->ExecQuery( L"WQL",
> L"select * from MSNdis_MediaConnectStatus where
> "
> "InstanceName =""\Intel(R) PRO/1000 MT Network
> Connection\"" ,
> WBEM_FLAG_FORWARD_ONLY |
> WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &enumerator );
Likewise:
hr = service->ExecQuery(WideString("WQL"), WideString("select * from
MSNdis_MediaConnectStatus where InstanceName = "\Intel(R) PRO/1000 MT
Network Connection\""), ...);
> CoUninitialize();
All of your error handling is exiting your function without calling
CoUninitialize(). You need to call CoUninitialize() for every successful
call to CoInitialize/Ex(), regardless of how your code exits, ie:
{
HRESULT hr = ::CoInitialize(NULL);
if( FAILED(hr) )
{
ShowMessage("COM initialization failed");
return;
}
// ...
if( FAILED(hr) )
{
//...
CoUninitialize(); // <-- add this each time
return;
}
}
If you do not want to call CoUninitialize() manually before each 'return',
then I suggest you change you use the TInitOle class instead of calling
CoInitialize/Ex() manually, ie:
{
TInitOle ole; // constructor calls CoInitialize/Ex()
if( !ole ) // check the result
{
ShowMessage("COM initialization failed");
return;
}
// the rest of your code here ...
// TInitOle destructor will call CoUnitialize() automatically when
the object goes out of scope...
}
Gambit
Technical Details
Message-ID:
<478ba4ea$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder6.cambrium.nl!feed.tweaknews.nl!news.astraweb.com!border2.a.newsrouter.astraweb.com!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<478b8203$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,382c3d02983b6dd6 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <478b8203$1@newsgroups.borland.com> Subject: Re: WMI Network unplugged Date: Mon, 14 Jan 2008 10:05:50 -0800 Lines: 75 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <478ba4ea$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1200334058 207.178.157.90 (14 Jan 2008 10:07:38 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder6.cambrium.nl!feed.tweaknews.nl!news.astraweb.com!border2.a.newsrouter.astraweb.com!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail