I’m trying to make a call to a method call called GetDevicesList in an interface called StillIamge and I am getting back empty results. I think it is a pointer problem but I’m not a C++ expert and I think that is the problem. The method call is:
HRESULT GetDeviceList(
DWORD dwType,
DWORD dwFlags,
[out] DWORD *pdwItemsReturned,
[out] LPVOID *ppBuffer
);
I know it is working as when I plug imaging devices in and out eh nubmer of returned devices goes up and down. The fact that the result is blank I think is due to me not getting the pointers correct – could someone take a quick look and let me knwo if that is the reason please?
#include "stdafx.h"
bool debug = true;
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwStiTotal = 0;
PSTI pSti = NULL;
HRESULT hres = StiCreateInstance(GetModuleHandle(NULL), STI_VERSION, &pSti, NULL);
STI_DEVICE_INFORMATION deviceInfo[255];
memset(deviceInfo,0, sizeof(deviceInfo));
hres = pSti->GetDeviceList(NULL, NULL, &dwStiTotal, (LPVOID*) deviceInfo);
printf("number devices %d\n", dwStiTotal);
for (int i=0; i<dwStiTotal; i++){
printf("---------------------------------------------------\n");
printf("type %d\n", deviceInfo[i].DeviceType);
printf("vendor %s\n", deviceInfo[i].pszVendorDescription);
printf("device %s\n", deviceInfo[i].pszDeviceDescription);
printf("portname %s\n", deviceInfo[i].pszPortName);
printf("PropProvider %s\n", deviceInfo[i].pszPropProvider);
printf("LocalName %s\n", deviceInfo[i].pszLocalName);
printf("InternalName %s\n", deviceInfo[i].szDeviceInternalName);
}
pSti->Release();
if (debug){
char key;
std::cin >> key;
}
return 0;
}
Thanks very much in advance and sorry for asking such a basic question!
Regards,
Neil
If you check the reference for
GetDeviceList, the last parameter ppBuffer is a (pointer to a) handle to an STI-allocated buffer. You are trying to send it a buffer you allocated yourself, I believe this should even be crashing somehow…Anyway, here is the proper way to do it
And what we get back is a pointer to an array of
STI_DEVICE_INFORMATIONitems, allocated by STI itself. Once you are done with it, you need to release it withLocalFree.