Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <windows.h>
#include <iostream>
#include <winioctl.h>
using namespace std;

BOOL GetDiskInfo(CHANGER_PRODUCT_DATA *Data)
{
	HANDLE hDevice;
	BOOL bResult;
	DWORD junk;

	hDevice = CreateFile(TEXT("\\\\.\\c:"),
		GENERIC_READ,
	FILES_HARE_READ|FILE_SHARE_WRITE,
	NULL,
	OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

	if(hDevice == INVALID_FILE_VALUE)
	{
		cout<<could not access disk\n;
		return FALSE;
	}

	bResult = DviceIoControl(hDevice,IOCTL_CHANGER_PRODUCT_DATA,NULL,0,Data,sizeof(*Data),&junk,				(LPOVERLAPPED)	NULL);

	closeHandle(hDevice);
	return (bResult);
}

int main()
{
	CHANGER_PRODUCT_DATA Data;

	if(!GetDiskInfo(&Data)
	{
		cout<<Coul not rtrieve seial nuimber\n"
		exit(0);
	}

	cout<<Data.SerialNumber<<"\n";

	return 1;
}
Posted
Updated 5-May-11 6:54am
v4

How can this code compile? There are lots of typos inside...

Your GetDiskInfo function is not correct. Use this one:
C++
BOOL GetDiskInfo(CHANGER_PRODUCT_DATA *Data)
{
    HANDLE hDevice;
    BOOL bResult;
    DWORD junk;
 
    hDevice = CreateFile(_T("\\\\.\\C:"),
        0,
        FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        0,
        NULL);
 
    if(hDevice == INVALID_HANDLE_VALUE)
    {
        cout << "could not access disk\n";
        return FALSE;
    }
 
    bResult = DeviceIoControl(hDevice,
        IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
        NULL,
        0,
        Data,
        sizeof(*Data),
        &junk,
        NULL);
    CloseHandle(hDevice);
    return bResult;
}
 
Share this answer
 
v3
From MSDN[^]:

Return Value

If the operation completes successfully, the return value is nonzero.

If the operation fails or is pending, the return value is zero. To get extended error information, call GetLastError.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900