我正在尝试调用KernelIoControl但无法在任何地方找到头文件pkfuncs.h。
我想知道: a)我需要秘密下载吗? b)或者它不存在,因为我正在使用的设备的SDK(卡西欧)不包括这些库?
另外......大概是WINAPI?我想我只是动态链接到它。
答案 0 :(得分:1)
您不需要标头来调用KernelIoControl。只需将其添加到您自己的应用中:
extern "C" BOOL KernelIoControl(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned
);
链接器会为您找到它。
答案 1 :(得分:0)
在我的搜索中,我发现this page对于获取IOCTRL_HAL_GET_DEVICEID非常有用:
它还详细说明了使用该调用所必需的DEVICE_ID结构:
#define IOCTL_HAL_GET_DEVICEID CTL_CODE(FILE_DEVICE_HAL, 21, METHOD_BUFFERED, FILE_ANY_ACCESS)
typedef struct _DEVICE_ID {
DWORD dwSize;
DWORD dwPresetIDOffset;
DWORD dwPresetIDBytes;
DWORD dwPlatformIDOffset;
DWORD dwPlatformIDBytes;
} DEVICE_ID, *PDEVICE_ID;
不一定明显的是,给定偏移量中包含的数据只是int值,最好被视为十六进制代码。
答案 2 :(得分:-1)
以下是我用来获取唯一设备ID的代码:
PDWORD pdwTmp;
DWORD dwUIDLen;
DWORD dwLen;
DWORD dwIdx;
BYTE abData[512];
BYTE abID[64];
PDEVICE_ID pDvcID;
dwLen = 0;
memset(abID, 0, sizeof(abID));
memset(abData, 0, sizeof(abData));
pDvcID = (PDEVICE_ID) abData;
pDvcID->dwSize = sizeof(abData);
KernelIoControl(IOCTL_HAL_GET_DEVICEID, NULL, 0, abData, sizeof(abData), &dwLen);
// If valid data was returned build ID from both parts
if ( (dwLen >= (sizeof(*pDvcID) + 8)) // Enough bytes returned for struct and 8 ID bytes
&& (dwLen >= pDvcID->dwSize) // Bytes returned is at least indicated struct size
&& pDvcID->dwPresetIDBytes && pDvcID->dwPlatformIDBytes // Both ID's are present
&& (pDvcID->dwPresetIDOffset >= sizeof(*pDvcID)) // Preset ID offset is reasonable
&& (pDvcID->dwPlatformIDOffset >= sizeof(*pDvcID)) // Platform ID offset is reasonable
&& ((pDvcID->dwPresetIDOffset + pDvcID->dwPresetIDBytes) // Preset ID is in bounds
<= pDvcID->dwSize)
&& ((pDvcID->dwPlatformIDOffset + pDvcID->dwPlatformIDBytes)// Platform ID is in bounds
<= pDvcID->dwSize) )
{
// Copy as much of the Preset ID as will fit
dwIdx = pDvcID->dwPresetIDBytes;
if ( dwIdx > sizeof(abID) )
dwIdx = sizeof(abID);
if ( dwIdx )
memcpy(abID, abData + pDvcID->dwPresetIDOffset, dwIdx);
dwLen = dwIdx;
// Copy as much of the Platform ID as will fit
dwIdx = pDvcID->dwPlatformIDBytes;
if ( dwIdx > (sizeof(abID) - dwLen) )
dwIdx = (sizeof(abID) - dwLen);
if ( dwIdx )
memcpy(abID + dwLen, abData + pDvcID->dwPlatformIDOffset, dwLen);
dwLen += dwIdx;
}