473,662 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

identifier not found error, undeclared identifier

Hi,
I have this code that I am trying to compile, but I am getting the
following errors

'CoInitializeSe curity': 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(NU LL);
//Security needs to be initialized in XP first and this was the major
problem
//why it was not working in XP.

if(CoInitialize Security( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEV EL_PKT,
RPC_C_IMP_LEVEL _IMPERSONATE,
NULL,
EOAC_NONE,
0)
!= S_OK)
return;

IWbemLocator * pIWbemLocator = NULL;
IWbemServices * pWbemServices = NULL;
IEnumWbemClassO bject * pEnumObject = NULL;

BSTR bstrNamespace = (L"root\\cimv2" );
if(CoCreateInst ance (
CLSID_WbemAdmin istrativeLocato r,
NULL ,
CLSCTX_INPROC_S ERVER | CLSCTX_LOCAL_SE RVER ,
IID_IUnknown ,
( void ** ) & pIWbemLocator
) != S_OK)
return;

if(pIWbemLocato r->ConnectServe r(
bstrNamespace, // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServic es
) != S_OK)
return;
HRESULT hRes;
// BSTR strQuery = (L"Select * from win32_Processor ");
BSTR strQuery = (L"SELECT * FROM Win32_Operating System");
// BSTR strQuery = (L"SELECT Name, ProcessId, Caption, ExecutablePath"
FROM Win32_Process") ;

// BSTR strQuery = (L"SELECT * FROM Win32_Process") ;

BSTR strQL = (L"WQL");
hRes = pWbemServices-
>ExecQuery(strQ L,strQuery,WBEM _FLAG_RETURN_IM MEDIATELY,NULL, &pEnumObject );
if(hRes != S_OK)
{
printf("Could not execute Query");
return;
}

ULONG uCount = 1, uReturned;
IWbemClassObjec t * pClassObject = NULL;

hRes = pEnumObject->Reset();

if(hRes != S_OK)
{
printf("Could not Enumerate");
return;
}

hRes = pEnumObject->Next(WBEM_INFI NITE,uCount, &pClassObjec t,
&uReturned);
if(hRes != S_OK)
{
printf("Could not Enumerate");
return;
}
VARIANT v1;
BSTR strClassProp = SysAllocString( L"NumberOfProce sses");
hRes = pClassObject->Get(strClassPr op, 0, &v1, 0, 0);

if(hRes != S_OK)
{
printf("Could not Get Value");
return;
}

SysFreeString(s trClassProp);

_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

Feb 25 '07 #1
3 5948
aa******@gmail. com wrote:
Hi,
I have this code that I am trying to compile, but I am getting the
following errors

'CoInitializeSe curity': 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.
Feb 25 '07 #2
* aa******@gmail. com:
Hi,
Hi.

PLEASE DON'T CROSSPOST TO ENVIRONMENT-SPECIFIC GROUPS AND CLC++.

Follow-ups set for pure C++ responses.

I have this code that I am trying to compile, but I am getting the
following errors

'CoInitializeSe curity': identifier not found
This means you haven't declared that identifier, most probably you've
forgotten to include some header.

'EOAC_NONE' : undeclared identifier
Ditto.

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>
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).

#ifdef _DEBUG
#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'...

#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

void OnButtonGetinfo ()
{
// TODO: Add your control notification handler code here
CoInitialize(NU LL);
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]
int _tmain(int argc, _TCHAR* argv[])
This is not a standard C++ startup function.

Moreover it's braindead even for this program's intended environment.

Use standard 'main'.

Any help I can get will be appreciated. Thanks
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?
Feb 26 '07 #3
On 26 Feb, 00:28, aarth...@gmail. com wrote:
Hi,
I have this code that I am trying to compile, but I am getting the
following errors

'CoInitializeSe curity': 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
CoInitializeSec urity.

Chris

Feb 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4835
by: Saurabh Aggrawal | last post by:
Hi, if (iter->m_name.compare(pstrName) == 0) { // Provide our object. *ppunkItem = iter->m_pUnknown; // Addref our object... iter->m_pUnknown->AddRef(); break; }
5
4128
by: Marc Gustafson | last post by:
This function is executed when a application file is double-clicked to open in a VC++ application. Specifically, this function is enabled by RegisterShellFileTypes () in the application's InitInstance. However, under MFC 7.1 for VC++ .NET 2003, CFrameWnd::OnDDEExecute has a bug that repeatedly generates this error message in the debugger Error: failed to execute DDE command ''.
0
1490
by: Stephanie Doherty | last post by:
Hello World, I am trying to use a _spawnl function like this (and I have included the process.h file): _spawnl(_P_WAIT,iporgfile,iporgfile,NULL); It compiles with the following errors: error C2065: '_P_WAIT' : undeclared identifier
2
1829
by: VicVic | last post by:
Hello, I have an old project, built with VC++. Now need to be compiled in Visual Studio .Net 2003. The project is going to build a DLL. When i try to compile the project, i got the following errors: c:\thepath\aaa.cpp(890): error C2065: 'm_nBackStyle' : undeclared identifier c:\thepath\aaa.cpp(890): error C3861: 'm_nBackStyle': identifier not found, even with argument-dependent lookup
4
3646
by: Ian Harding | last post by:
I am investigating the upgrade of a VC++ 6 project to build in VS 2005. There is a compiler error in one of the MFC files - afxcomctl32.inl. The message is: error C2065: 'afxComCtlWrapper' : undeclared identifier. The odd thing is that if I hover over afxComCtlWrapper in the source code, the intellisense shows that it is declared and right-click "Go to Declaration" takes me to line 25 of afxwin.h which contains #define...
2
19847
by: aarthi28 | last post by:
Hi, 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
5
12518
by: vmagana | last post by:
First of all I would like to indicate that I am a newbie a programming. I am having a problem compiling a sample source code that I downloaded from microsoft. When I try to build the program I get an error that 'STORAGE_PROPERTY_QUERY' undeclared identifier. This structure is defined in the ntddstor.h file and is included. I dont understand why it does not see this structure. OS: Windows XP, Visual C++ 6.0, latest SDK and changed the...
3
3286
by: Anna Smidt | last post by:
Thanks for the help so far. I have some problems left. One of them is an undeclared identifier, but it's unclear to me why the compiler fights with me. It says "iter: undeclared identifier" I thought that the identifier was clear: "int", or is int just the declaration, and the identifier is something else? Thanks a lot.
6
38048
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
1
2585
by: LuxCkrown | last post by:
Hey everyone, i've been browsing for a fix to my problem 1>c:\documents and settings\user\desktop\judis_repack\judis repack\judis repack\maplestoryserver\inventory.cpp(386) : error C2065: 'amount' : undeclared identifier I've found some solutions but I'm not sure how they pertain to my problem. If possible, would there be any general methods of resolving such undeclared identifier problems? This is the string, I'm a complete beginner so i'm...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.