我正在从事有关IR跟踪的项目,并且正在使用FreeTrack(www.free-track.net)软件。 FreeTrack提供了一个sdk文件夹,其中包含C,Matlab和delphi代码的下载文件,可用于将FreeTrack的数据以这些语言之一与自己的编写程序进行接口(interface)。
我开始使用Matlab,但是当matlab遇到问题时,我继续使用Mvisual进行C++。这也带来了一个问题,在Matlab中似乎也是如此。
这是东西:
当我想从freetrack客户端的DLL中读取数据时,我使用:
//declare imported function pointers
importGetData getData;
getData = (importGetData)GetProcAddress(hinstLib, "FTGetData");
if (getData(pData))
printf("Yaw: %f\n", data.yaw);
第一次运行,但是数据为0。第二次运行,Mvisual给出了错误:
Unhandled exception at 0xc3618000 in FreeTrack.exe: 0xC0000005: Access violation
reading location 0xc3618000.
getData的地址为0xc3618000。
这仅在FreeTrack运行时发生。如果不存在,则不会从getData返回任何数据。
知道这是什么吗?
原始代码:
#include <windows.h>
#include <stdio.h>
#include <conio.h>
typedef struct
{
float yaw;
float pitch;
float roll;
float x;
float y;
float z;
int dataID;
}FreeTrackData;
// DLL function signatures
// These match those given in FTTypes.pas
// WINAPI is macro for __stdcall defined somewhere in the depths of windows.h
typedef bool (WINAPI *importGetData)(FreeTrackData * data);
typedef char *(WINAPI *importGetDllVersion)(void);
typedef void (WINAPI *importReportID)(int name);
typedef char *(WINAPI *importProvider)(void);
int main(int argc, char **argv)
{
/*while(1){
printf("hello");
}*/
//declare imported function pointers
importGetData getData;
importGetDllVersion getDllVersion;
importReportID reportID;
importProvider provider;
// create variables for exchanging data with the dll
FreeTrackData data;
FreeTrackData *pData;
pData = &data;
char *pDllVersion;
int name = 453;
char *pProvider;
//while(1){};
// Load DLL file
HINSTANCE hinstLib = LoadLibrary("FreeTrackClient.dll");
if (hinstLib == NULL) {
printf("ERROR: unable to load DLL\n");
//return 1;
while(1){};
}
else
{
printf("dll loaded\n");
}
//while(1){};
// Get function pointers
getData = (importGetData)GetProcAddress(hinstLib, "FTGetData");
getDllVersion = (importGetDllVersion)GetProcAddress(hinstLib, "FTGetDllVersion");
//reportID = (importReportID)GetProcAddress(hinstLib, "FTReportID");
reportID = (importReportID)GetProcAddress(hinstLib, "FTReportName");
provider = (importProvider)GetProcAddress(hinstLib, "FTProvider");
// Check they are valid
if (getData == NULL) {
printf("ERROR: unable to find 'FTGetData' function\n");
FreeLibrary(hinstLib);
//return 1;
}
if (getDllVersion == NULL){
printf("ERROR: unable to find 'FTGetDllVersion' function\n");
FreeLibrary(hinstLib);
//return 1;
}
if (reportID == NULL){
printf("ERROR: unable to find 'FTReportID' function\n");
FreeLibrary(hinstLib);
//return 1;
}
if (reportID == NULL){
printf("ERROR: unable to find 'FTProvider' function\n");
FreeLibrary(hinstLib);
//return 1;
}
// Print the address of each function
printf("FTGetData is at address: 0x%x\n",getData);
printf("FTGetDllVersion is at address: 0x%x\n",getDllVersion);
printf("FTReportID is at address: 0x%x\n",reportID);
printf("FTProvider is at address: 0x%x\n",provider);
// Call each function and display result
pDllVersion = getDllVersion();
printf("Dll Version: %s\n", pDllVersion);
pProvider = provider();
printf("Provider: %s\n", pProvider);
reportID(name); //not sure what this does - I guess it tells the dll that I am using it.
system("pause"); //wait till keyboard is pressed before entering main loop
while( kbhit() != 1)
{
//system("cls"); //clear screen
if (getData(pData))
{
printf("Provider: %s\n", pProvider);
printf("Record ID: %d\n" , data.dataID);
printf("Yaw: %5.2f\n" , data.yaw );
printf("Pitch: %5.2f\n" , data.pitch );
printf("Roll: %5.2f\n" , data.roll );
printf("X: %5.2f\n" , data.x );
printf("Y: %5.2f\n" , data.y );
printf("Z: %5.2f\n" , data.z );
}
else
{
printf("Nothing returned from getData\n");
break;
}
}
// Unload DLL file
FreeLibrary(hinstLib);
return 0;
}
最佳答案
您告诉printf
,yaw
是C风格的字符串,但它是浮点数!
关于c++ - 访问冲突读取位置0xc3618000,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9291932/