Thread: [Dev-C++] Dev-C++: problem compiling WMI sample program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: shaji m. <sha...@gm...> - 2005-07-04 13:37:32
|
Hi, Has anyone tried this before or have ideas about how to solve the problem ? What I want to do: Compile the WMI sample program below (from http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/wmisdk/w= mi/example_creating_a_wmi_application.asp) using Dev-C++ . ---------------------------------------------------------------------------= --------------------------- #define _WIN32_DCOM #include <iostream> using namespace std; #include <comdef.h> #include <Wbemidl.h> # pragma comment(lib, "wbemuuid.lib") int main(int argc, char **argv) { HRESULT hres; // Initialize COM. hres =3D CoInitializeEx(0, COINIT_MULTITHREADED); if (FAILED(hres)) { cout << "Failed to initialize COM library. " << "Error code =3D 0x" << hex << hres << endl; return 1; // Program has failed. } // Initialize hres =3D CoInitializeSecurity( NULL, =20 -1, // COM negotiates service =20 NULL, // Authentication services NULL, // Reserved RPC_C_AUTHN_LEVEL_DEFAULT, // authentication RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation NULL, // Authentication info EOAC_NONE, // Additional capabilities NULL // Reserved ); =20 if (FAILED(hres)) { cout << "Failed to initialize security. " << "Error code =3D 0x" << hex << hres << endl; CoUninitialize(); return 1; // Program has failed. } // Obtain the initial locator to Windows Management // on a particular host computer. IWbemLocator *pLoc =3D 0; hres =3D CoCreateInstance( CLSID_WbemLocator, =20 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc); =20 if (FAILED(hres)) { cout << "Failed to create IWbemLocator object. " << "Error code =3D 0x" << hex << hres << endl; CoUninitialize(); return 1; // Program has failed. } IWbemServices *pSvc =3D 0; // Connect to the root\cimv2 namespace with the // current user and obtain pointer pSvc // to make IWbemServices calls. hres =3D pLoc->ConnectServer( =20 _bstr_t(L"ROOT\\CIMV2"), // WMI namespace NULL, // User name NULL, // User password 0, // Locale NULL, // Security flags =20 0, // Authority =20 0, // Context object &pSvc // IWbemServices proxy ); =20 =20 if (FAILED(hres)) { cout << "Could not connect. Error code =3D 0x" << hex << hres << endl; pLoc->Release(); =20 CoUninitialize(); return 1; // Program has failed. } cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; // Set the IWbemServices proxy so that impersonation // of the user (client) occurs. hres =3D CoSetProxyBlanket( =20 pSvc, // the proxy to set RPC_C_AUTHN_WINNT, // authentication service RPC_C_AUTHZ_NONE, // authorization service NULL, // Server principal name RPC_C_AUTHN_LEVEL_CALL, // authentication level RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level NULL, // client identity EOAC_NONE // proxy capabilities =20 ); if (FAILED(hres)) { cout << "Could not set proxy blanket. Error code =3D 0x" << hex << hres << endl; pSvc->Release(); pLoc->Release(); =20 CoUninitialize(); return 1; // Program has failed. } // Use the IWbemServices pointer to make requests of WMI. // Make requests here: // For example, query for print queues that // have more than 10 jobs IEnumWbemClassObject* pEnumerator =3D NULL; hres =3D pSvc->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * Win32_PerfFormattedData_Spooler_PrintQueue " "Where Name <> '_Total'"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); =20 if (FAILED(hres)) { cout << "Query for print queues failed. " << "Error code =3D 0x" << hex << hres << endl; pSvc->Release(); pLoc->Release(); =20 CoUninitialize(); return 1; // Program has failed. } else { do { IWbemClassObject* pInstance =3D NULL; ULONG dwCount =3D NULL; hres =3D pEnumerator->Next( WBEM_INFINITE, 1, &pInstance, &dwCount); =20 =20 } while (hres =3D=3D WBEM_S_NO_ERROR); =20 } =20 // Cleanup // =3D=3D=3D=3D=3D=3D=3D=3D pSvc->Release(); pLoc->Release(); =20 CoUninitialize(); return 0; // Program successfully completed. } ---------------------------------------------------------------------------= --------------------------- What I tried: Installed Dev-C++ 4.9.9.2 on my Windows 2000 machine and tried to compile the program - the compiler complained about not being able to find comdef.h. So downloaded the Windows SDK from MSDN and installed it (From the ISO image 5.2.3790.1830.15.PlatformSDK_Svr2003SP1_rtm.img after burning a CD with it). Added the SDK include and lib directories in the project options. Now the top of the compile log looks like this - the compiler gives me 470 errors ! ---------------------------------------------------------------------------= --------------------------- Compiler: Default compiler Building Makefile: "D:\shaji\projects\WMIsample\Makefile.win" Executing make... make.exe -f "D:\shaji\projects\WMIsample\Makefile.win" all g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"=20 -I"C:/Dev-Cpp/include/c++/3.4.2/backward"=20 -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"=20 -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"=20 -I"C:/Program Files/Microsoft Platform SDK/Include" -I"C:/Program Files/Microsoft Platform SDK/Include/crt" In file included from C:/Program Files/Microsoft Platform SDK/Include/crt/comutil.h:17, from C:/Program Files/Microsoft Platform SDK/Include/comdef.h:23, from main.cpp:4: C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:660:19: invalid suffix "ui64" on integer constant C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:1356:19: invalid suffix "ui64" on integer constant C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:2145:19: invalid suffix "ui64" on integer constant C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:2356:19: invalid suffix "i64" on integer constant C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:2358:23: invalid suffix "i64" on integer constant C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:2769:19: invalid suffix "ui64" on integer constant C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:2937:19: invalid suffix "ui64" on integer constant C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:3105:19: invalid suffix "ui64" on integer constant In file included from C:/Program Files/Microsoft Platform SDK/Include/crt/comutil.h:17, from C:/Program Files/Microsoft Platform SDK/Include/comdef.h:23, from main.cpp:4: C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h: In function `HRESULT ULongLongMult(long long unsigned int, long long unsigned int, long long unsigned int*)': C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:3129: error: integer constant is too large for "long" type C:/Program Files/Microsoft Platform SDK/Include/crt/intsafe.h:3135: error: integer constant is too large for "long" type In file included from C:/Program Files/Microsoft Platform SDK/Include/comdef.h:23, from main.cpp:4: C:/Program Files/Microsoft Platform SDK/Include/crt/comutil.h: At global sc= ope: C:/Program Files/Microsoft Platform SDK/Include/crt/comutil.h:45: error: invalid use of undefined type `struct _com_error' ---------------------------------------------------------------------------= --------------------------- I did a Google search for ui64 and came across this in the change log for lcc-win32 (http://www.q-software-solutions.de/products/lcc-win32/change= log.shtml): The compiler now recognizes I64 and UI64 as suffixes equivalent to LL and ULL to remain compatible with Microsoft notation. No warnings were given when a long long constant overflowed. Fixed. Might the compiler in Dev-C++ need changes along these lines ? Or is there some simple solution ? Regards Shaji Mathew |