问题
关于void**指针数组的问题,函数形参是指针数组,调用的地址是一样的,但里面的数据不对
DLL中调用函数的代码,其中void**是一个指针数组。
//查找设备
int FindDevices(void** devices, int maxCount)
{
U32 i;
PLX_STATUS rc;
PLX_DEVICE_KEY DevKey;
int connectCount=0;
i = 0;
do
{
// Reset device key structure
memset(&DevKey, PCI_FIELD_IGNORE, sizeof(PLX_DEVICE_KEY));
// Check if device exists
rc =PlxPci_DeviceFind(
&DevKey,
(U8)i
);
if (rc == ApiSuccess)
{
if ((DevKey.VendorId == VENDER_ID) && (DevKey.DeviceId == 0x9101))
{
devices[connectCount]=(void *)&DevKey;
connectCount++;
//return connectCount;
}
i++;
}
} while ((rc == ApiSuccess) && (i < maxCount));
return connectCount;
}
主函数中调用Dll,然后打印里面的数据。
int main(int argc, const char *argv[])
{
PLX_DEVICE_KEY **devices= NULL;
int count;
devices = (PLX_DEVICE_KEY **)malloc(sizeof(PLX_DEVICE_KEY)*10);
count = FindDevices((void**)devices,10);
printf("%p\n",devices);
if(count == 0)
{
printf("count == 0");
}
else
{
printf("VID: %X , PID:%X",devices[0]->VendorId,devices[0]->DeviceId);
}
getchar();
return 0;
}
运行结果及报错内容
在dll内部地址和数据是一致的,回到main函数后地址一直数据却不一致
指针和内存这部分比较薄弱,希望指点一二