gpt4 book ai didi

c++ - 读取位置 0xc3618000 访问冲突

转载 作者:行者123 更新时间:2023-12-02 09:04:26 25 4
gpt4 key购买 nike

我正在开发一个有关红外跟踪的项目,并且正在使用 FreeTrack (www.free-track.net) 软件。 FreeTrack 提供了一个 sdk 文件夹,其中包含 C、Matlab 和 delphi 代码,可用于将 FreeTrack 中的数据连接到您自己使用其中一种语言编写的程序。

我从 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 样式字符串,但它是一个 float !

关于c++ - 读取位置 0xc3618000 访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9291932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com