Click here to Skip to main content
15,907,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Elliminate the e symbol from doubles Pin
Schehaider_Aymen24-Jun-10 0:06
Schehaider_Aymen24-Jun-10 0:06 
GeneralRe: Elliminate the e symbol from doubles Pin
Niklas L24-Jun-10 0:15
Niklas L24-Jun-10 0:15 
GeneralRe: Elliminate the e symbol from doubles Pin
Niklas L24-Jun-10 0:17
Niklas L24-Jun-10 0:17 
AnswerRe: Elliminate the e symbol from doubles Pin
Aescleal24-Jun-10 0:22
Aescleal24-Jun-10 0:22 
GeneralRe: Elliminate the e symbol from doubles Pin
Schehaider_Aymen24-Jun-10 0:25
Schehaider_Aymen24-Jun-10 0:25 
AnswerRe: Elliminate the e symbol from doubles Pin
norish24-Jun-10 1:07
norish24-Jun-10 1:07 
GeneralRe: Elliminate the e symbol from doubles Pin
Schehaider_Aymen24-Jun-10 2:11
Schehaider_Aymen24-Jun-10 2:11 
GeneralRe: Elliminate the e symbol from doubles Pin
Richard MacCutchan24-Jun-10 2:53
mveRichard MacCutchan24-Jun-10 2:53 
QuestionHow to do Modulo (double and Big Numbers) Pin
Schehaider_Aymen23-Jun-10 21:50
Schehaider_Aymen23-Jun-10 21:50 
AnswerRe: How to do Modulo (double and Big Numbers) Pin
Richard MacCutchan23-Jun-10 21:59
mveRichard MacCutchan23-Jun-10 21:59 
GeneralRe: How to do Modulo (double and Big Numbers) Pin
Schehaider_Aymen23-Jun-10 22:07
Schehaider_Aymen23-Jun-10 22:07 
AnswerRe: How to do Modulo (double and Big Numbers) Pin
CPallini23-Jun-10 22:01
mveCPallini23-Jun-10 22:01 
AnswerRe: How to do Modulo (double and Big Numbers) Pin
Peter_in_278023-Jun-10 22:02
professionalPeter_in_278023-Jun-10 22:02 
GeneralRe: How to do Modulo (double and Big Numbers) Pin
Schehaider_Aymen23-Jun-10 22:10
Schehaider_Aymen23-Jun-10 22:10 
GeneralRe: How to do Modulo (double and Big Numbers) Pin
Schehaider_Aymen23-Jun-10 22:37
Schehaider_Aymen23-Jun-10 22:37 
AnswerRe: How to do Modulo (double and Big Numbers) Pin
Niklas L23-Jun-10 23:33
Niklas L23-Jun-10 23:33 
GeneralRe: How to do Modulo (double and Big Numbers) Pin
Schehaider_Aymen24-Jun-10 0:17
Schehaider_Aymen24-Jun-10 0:17 
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.

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.