I'm trying to call KernelIoControl but can't find the header file pkfuncs.h anywhere.

I'm wondering if: a) Is there a secret download I need? b) Or is it not present because the device's SDK I'm using (Casio) does not include these libraries?

Also ... presumably it's WINAPI? I think I'll just dynamically link to it.

有帮助吗?

解决方案 2

In my searching I also found this page very useful on getting the IOCTRL_HAL_GET_DEVICEID:

It also details the DEVICE_ID structure, which is necessary to use the call:

#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; 

What isn't necessarily obvious is that the data contained at the given offsets are just int values, and probably best viewed as hex codes.

其他提示

You don't need the header to call KernelIoControl. Just add this to your own app:

extern "C" BOOL KernelIoControl(
  DWORD dwIoControlCode,
  LPVOID lpInBuf,
  DWORD nInBufSize,
  LPVOID lpOutBuf,
  DWORD nOutBufSize,
  LPDWORD lpBytesReturned
);

The linker will find it for you.

Here is code that I use to get a unique device 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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top