I met some very very weird issue using FindFirstDevice. I'm using Visual
Studio 2005 and WM5 PPC SDK
Following code works fine (either in emulator or real device -- imate JAQ3):
int _tmain(int argc, _TCHAR* argv[])
{
WCHAR * searchName= L"";
::DEVMGR_DEVICE_INFORMATION pdi;
HANDLE
h=::FindFirstDevice(DeviceSearchType::DeviceSearchByDeviceName,searchName,&pdi);
return 0;
}
but , if we call "FindFirstDevice" in a function not main, it won't work
(neither emulator nor real device work):
like following code, it would return -1.
void foo()
{
WCHAR * searchName= L"";
::DEVMGR_DEVICE_INFORMATION pdi;
HANDLE
h=::FindFirstDevice(DeviceSearchType::DeviceSearchByDeviceName,searchName,&pdi);
}
int _tmain(int argc, _TCHAR* argv[])
{
foo();
return 0;
}
Or even we just call a memset to set pdi to 0 , it won't work
int _tmain(int argc, _TCHAR* argv[])
{
WCHAR * searchName= L"";
::DEVMGR_DEVICE_INFORMATION pdi;
memset(&pdi,0,sizeof(DEVMGR_DEVICE_INFORMATION));
HANDLE
h=::FindFirstDevice(DeviceSearchType::DeviceSearchByDeviceName,searchName,&pdi);
return 0;
}
I"m pretty sure there must be something wrong with the implementation of
this function -- sounds it rely on some random memory.