OSError: exception: access violation reading 0x615C3A46
C++生成的dll库中的函数想加入路径变量:
错误代码
修改前:CreatDLL.h
// 错误是:string const &path
#pragma once
#ifdef CREATDLL_EXPORTS
#define CREATDLL_API __declspec(dllexport)
#else
#define CREATDLL_API __declspec(dllimport)
#endif // CREATDLL_EXPORTS
extern "C" CREATDLL_API void OpenglDLL(string const &path);
报错
修改后的:CreatDLL.h
// 错误是:string const &path
#pragma once
#ifdef CREATDLL_EXPORTS
#define CREATDLL_API __declspec(dllexport)
#else
#define CREATDLL_API __declspec(dllimport)
#endif // CREATDLL_EXPORTS
extern "C" CREATDLL_API void OpenglDLL(const char *path);
python代码
//
def CDopengl(self):
aaa=ctypes.CDLL('openglDLL.dll')
aaa.OpenglDLL(b"resources/policecharger/police.obj")
原因应该是ctypes库定义了一些与C兼容的数据类型,其中不包含string,这个bug卡了我很久,遂记录之!