Click here to Skip to main content
15,897,315 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to do Modulo (double and Big Numbers) Pin
Aescleal24-Jun-10 0:28
Aescleal24-Jun-10 0:28 
QuestionTHREAD PRIORITY Pin
MsmVc23-Jun-10 19:03
MsmVc23-Jun-10 19:03 
AnswerRe: THREAD PRIORITY Pin
«_Superman_»23-Jun-10 19:25
professional«_Superman_»23-Jun-10 19:25 
GeneralRe: THREAD PRIORITY Pin
MsmVc23-Jun-10 19:38
MsmVc23-Jun-10 19:38 
GeneralRe: THREAD PRIORITY Pin
«_Superman_»23-Jun-10 19:44
professional«_Superman_»23-Jun-10 19:44 
GeneralRe: THREAD PRIORITY Pin
MsmVc23-Jun-10 19:47
MsmVc23-Jun-10 19:47 
GeneralRe: THREAD PRIORITY Pin
Code-o-mat23-Jun-10 22:07
Code-o-mat23-Jun-10 22:07 
QuestionHow to get the SerialNumber of disk driver? Pin
whiteclouds23-Jun-10 18:22
whiteclouds23-Jun-10 18:22 
Hi all!
Now I am developing an application to read the disk driver's SerialNumber. I want to read it by WMI. The code is as following:
BOOL CData::GetSerialNumber(BYTE* out)
{
	BOOL bRet = FALSE;
	HRESULT hr;
	hr = CoInitializeEx(0, COINIT_MULTITHREADED); 
	if (FAILED(hr)) 
	{
		cout << "Failed to initialize COM library. Error code = 0x"
		   << hex << hr << endl; 
	  return bRet;
	}
	hr =  CoInitializeSecurity(
		NULL,                      // Security descriptor    
		-1,                        // COM negotiates authentication service
		NULL,                      // Authentication services
		NULL,                      // Reserved
		RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication level for proxies
		RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation level for proxies
		NULL,                        // Authentication info
		EOAC_NONE,                   // Additional capabilities of the client or server
		NULL);                       // Reserved

	if (FAILED(hr))
	{
	   cout << "Failed to initialize security. Error code = 0x" 
			<< hex << hr << endl;
	   CoUninitialize();
	   return bRet;                  // Program has failed.
	}
    IWbemLocator *pLoc = 0;

    hr = CoCreateInstance(CLSID_WbemLocator, 0, 
        CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
 
    if (FAILED(hr))
    {
        cout << "Failed to create IWbemLocator object. Err code = 0x"
             << hex << hr << endl;
        CoUninitialize();
        return bRet;     // Program has failed.
    }
	IWbemServices *pSvc = 0;

    // Connect to the root\default namespace with the current user.
    hr = pLoc->ConnectServer(
            BSTR(L"ROOT\\CIMV2"), 
            NULL, NULL, 0, NULL, 0, 0, &pSvc);

    if (FAILED(hr))
    {
        cout << "Could not connect. Error code = 0x" 
             << hex << hr << endl;
        pLoc->Release();
        CoUninitialize();
        return bRet;      // Program has failed.
    }

    cout << "Connected to WMI" << endl;
    HRESULT hres;

    // Set the proxy so that impersonation of the client occurs.
    hres = CoSetProxyBlanket(pSvc,
       RPC_C_AUTHN_WINNT,
       RPC_C_AUTHZ_NONE,
       NULL,
       RPC_C_AUTHN_LEVEL_CALL,
       RPC_C_IMP_LEVEL_IMPERSONATE,
       NULL,
       EOAC_NONE
    );

    if (FAILED(hres))
    {
        cout << "Could not set proxy blanket. Error code = 0x" 
             << hex << hres << endl;
		pSvc->Release();
		pLoc->Release();
		CoUninitialize();
        return bRet;      // Program has failed.
    }
	//Now start reading...
	IEnumWbemClassObject* pObj = 0;
	IWbemClassObject* pwcObj = 0;
	hres = pSvc->ExecQuery(L"WQL",L"select * from Win32_PhysicalMedia",WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,0,
		&pObj);
	char strID[20];
	VARIANT vtData;
	CIMTYPE ctType = 0;
	long lFavor = 0;
	ULONG ulRet;
	if(SUCCEEDED(hres))
	{
		hres = pObj->Next(WBEM_INFINITE,1,&pwcObj,&ulRet);
		if(SUCCEEDED(hres) && pwcObj)
		{
			ZeroMemory(strID,20);
			vtData.pbstrVal = 0;
			hres = pwcObj->Get(L"SerialNumber",0,&vtData,&ctType,&lFavor);
			if(vtData.pbstrVal)
			{
				CopyMemory(strID,vtData.pbstrVal,20);
			}
			VariantClear(&vtData);
			pwcObj->Release();
			bRet = TRUE;
			if(SUCCEEDED(hres) && out)
			{
				CopyMemory(out,strID,20);
			}
		}
		pObj->Release();
	}
	//Clean up
	pSvc->Release();
	pLoc->Release();
	CoUninitialize();
	return bRet;
}

The variable vtData should contain the SerialNumber of the disk driver. But I am always get a value of NULL in vtData. And the return value from
Get(L"SerialNumber",0,&amp;vtData,&amp;ctType,&amp;lFavor);
is success. And I try to get some other data in pwcObj. They are all NULL. I don't know the reason. My disk driver is working well. I can get this number by some other software. I hope someone could be kind to tell me the right way. Thx! Smile | :)
There is some white cloud floating on the blue sky. That's the landscape I like.

AnswerRe: How to get the SerialNumber of disk driver? Pin
David Crow24-Jun-10 3:21
David Crow24-Jun-10 3:21 
QuestionReadProcessMemory() problem Pin
ALLERSLIT23-Jun-10 13:59
ALLERSLIT23-Jun-10 13:59 
AnswerRe: ReadProcessMemory() problem Pin
Richard Andrew x6423-Jun-10 14:20
professionalRichard Andrew x6423-Jun-10 14:20 
GeneralRe: ReadProcessMemory() problem Pin
ALLERSLIT23-Jun-10 14:23
ALLERSLIT23-Jun-10 14:23 
GeneralRe: ReadProcessMemory() problem Pin
ALLERSLIT23-Jun-10 14:44
ALLERSLIT23-Jun-10 14:44 
Questionchange color in c Pin
hasani200723-Jun-10 9:36
hasani200723-Jun-10 9:36 
AnswerRe: change color in c Pin
Rick York23-Jun-10 10:07
mveRick York23-Jun-10 10:07 
AnswerRe: change color in c Pin
Stephen Hewitt23-Jun-10 13:30
Stephen Hewitt23-Jun-10 13:30 
QuestionHow can a program in diferent PCs using the same DB be notified of a change? Pin
manchukuo23-Jun-10 9:14
manchukuo23-Jun-10 9:14 
AnswerRe: How can a program in diferent PCs using the same DB be notified of a change? Pin
Luc Pattyn23-Jun-10 9:28
sitebuilderLuc Pattyn23-Jun-10 9:28 
GeneralRe: How can a program in diferent PCs using the same DB be notified of a change? Pin
manchukuo23-Jun-10 16:24
manchukuo23-Jun-10 16:24 
GeneralRe: How can a program in diferent PCs using the same DB be notified of a change? Pin
Luc Pattyn23-Jun-10 16:39
sitebuilderLuc Pattyn23-Jun-10 16:39 
QuestionCan anyone please tell me why these initializations are causing BUS errors? Pin
M.manning23-Jun-10 8:47
M.manning23-Jun-10 8:47 
AnswerRe: Can anyone please tell me why these initializations are causing BUS errors? Pin
Code-o-mat23-Jun-10 9:06
Code-o-mat23-Jun-10 9:06 
GeneralRe: Can anyone please tell me why these initializations are causing BUS errors? Pin
M.manning23-Jun-10 9:26
M.manning23-Jun-10 9:26 
GeneralRe: Can anyone please tell me why these initializations are causing BUS errors? Pin
Code-o-mat23-Jun-10 9:35
Code-o-mat23-Jun-10 9:35 
AnswerRe: Can anyone please tell me why these initializations are causing BUS errors? Pin
Aescleal23-Jun-10 10:31
Aescleal23-Jun-10 10:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.