'CoInitializeSecurity': identifier not found
'EOAC_NONE' : undeclared identifier
I have pasted the code below
// Using_WMI1.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include "wbemidl.h"
#include <comdef.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void OnButtonGetinfo()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
//Security needs to be initialized in XP first and this was the major
problem
//why it was not working in XP.
if(CoInitializeSecurity( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
0)
!= S_OK)
return;
IWbemLocator * pIWbemLocator = NULL;
IWbemServices * pWbemServices = NULL;
IEnumWbemClassObject * pEnumObject = NULL;
BSTR bstrNamespace = (L"root\\cimv2");
if(CoCreateInstance (
CLSID_WbemAdministrativeLocator,
NULL ,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
IID_IUnknown ,
( void ** ) & pIWbemLocator
) != S_OK)
return;
if(pIWbemLocator->ConnectServer(
bstrNamespace, // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServices
) != S_OK)
return;
HRESULT hRes;
// BSTR strQuery = (L"Select * from win32_Processor");
BSTR strQuery = (L"SELECT * FROM Win32_OperatingSystem");
//BSTR strQuery = (L"SELECT Name, ProcessId, Caption, ExecutablePath"
FROM Win32_Process");
//BSTR strQuery = (L"SELECT * FROM Win32_Process");
BSTR strQL = (L"WQL");
hRes = pWbemServices-
Quote: Originally Posted by >ExecQuery(strQL,strQuery,WBEM_FLAG_RETURN_IMMEDIAT ELY,NULL,&pEnumObject); |
ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;
hRes = pEnumObject->Reset();
if(hRes != S_OK)
{
printf("Could not Enumerate");
return;
}
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject,
&uReturned);
if(hRes != S_OK)
{
printf("Could not Enumerate");
return;
}
VARIANT v1;
BSTR strClassProp = SysAllocString(L"NumberOfProcesses");
hRes = pClassObject->Get(strClassProp, 0, &v1, 0, 0);
if(hRes != S_OK)
{
printf("Could not Get Value");
return;
}
SysFreeString(strClassProp);
_bstr_t bstrPath = &v1; //Just to convert BSTR to ANSI
char* strPath=(char*)bstrPath;
if (SUCCEEDED(hRes))
printf(strPath);
else
printf("Error in getting object");
VariantClear( &v1 );
pIWbemLocator->Release();
pWbemServices->Release();
pEnumObject->Release();
pClassObject->Release();
CoUninitialize();
}
int _tmain(int argc, _TCHAR* argv[])
{
OnButtonGetinfo();
return 0;
}
Any help I can get will be appreciated. Thanks
Dear allI have made a program using Visual C++, and i get the exe program.Now, i want to give the ex...
By mahmoudouf
Okay, here goes :)I've been burying some hours trying to get an existing C dll (using __cdeclcalling...
By theunprofessional
When I try to sort my combo box I get the following error."Cannot sort a ComboBox that has a DataSou...
By raj
hi all i m doing aproject i visual C++ on image processing. i wan to extract the r g b colorof the ...
By vinnu
Hello all,I'm a beginner of COM programming, I have a exercise, but got a compileerror withComFortun...
By awin, 1 Comments
Hi All,In my VC7 application, I want to read particular binary file from CDimage. But that binary fi...
By rachit_goyal_gmail_com, 2 Comments
I am trying to write programs in C in a text editor and run them on a command line but I am having t...
By matt, 1 Comments
We write lots of cross platform code at my company. To facilitatethis, class declarations are handle...
By geoffrey, 1 Comments
Hi group,when using unmanaged class with my managed app, I've seen errors whenincluding (for example...
By nicolas_hilaire_motorola_com, 3 Comments
aarthi28...gmail.com wrote:
I have this code that I am trying to compile, but I am getting the
following errors
>
'CoInitializeSecurity': identifier not found
'EOAC_NONE' : undeclared identifier
>
I have pasted the code below
>
// Using_WMI1.cpp : Defines the entry point for the console
application.
//
>
This is a little off topic on comp.lang.c++.
--
Ian Collins.
iancollins | Fri, 04 Jan 2008 12:33:00 GMT |
* aarthi28...gmail.com:
Hi.
PLEASE DON'T CROSSPOST TO ENVIRONMENT-SPECIFIC GROUPS AND CLC++.
Follow-ups set for pure C++ responses.
following errors
>
'CoInitializeSecurity': identifier not found
This means you haven't declared that identifier, most probably you've
forgotten to include some header.
Ditto.
>
// Using_WMI1.cpp : Defines the entry point for the console
application.
//
>
#include "stdafx.h"
#include "wbemidl.h"
#include <comdef.h>
None of these are standard C++ headers. Most probably the intention is
that "stdafx.h" should drag in the headers you're missing. Update that
file to include the relevant headers (it's also a good idea to turn off
precompiled header support for your project -- the vendor-specific
variant you're using confuses novices endlessly, allows incorrect code
to compile, and sometimes means correct code doesn't compile).
#define new DEBUG_NEW
Redefining a C++ keyword means your code has undefined behavior if it
uses anything from the standard library. And since it apparently uses
'new'...
static char THIS_FILE[] = __FILE__;
#endif
>
>
>
void OnButtonGetinfo()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
Although environment-specific, this is a library initialization call.
It's generally unsafe to initialize libraries later than the start of
'main'. In particular, experience with this library is that late
initialization is extremely unsafe -- don't do it.
[snip]
This is not a standard C++ startup function.
Moreover it's braindead even for this program's intended environment.
Use standard 'main'.
You're welcome.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
alfp_steinbach | Fri, 04 Jan 2008 12:34:00 GMT |
On 26 Feb, 00:28, aarth......gmail.com wrote:
I have this code that I am trying to compile, but I am getting the
following errors
>
'CoInitializeSecurity': identifier not found
'EOAC_NONE' : undeclared identifier
A search on the VC subdirectories finds it in objidl.h, but you should
#include <objbase.h>
as is stated in the Requirements section of the MSDN description of
CoInitializeSecurity.
Chris
chris_doran_postmaster_co_uk | Fri, 04 Jan 2008 12:35:00 GMT |