我有一个非常简单的dll库头文件,但是它是用C ++编写的。任何人都可以帮助我编辑它以便与Matlab(本机C)中的“LoadLibrary”命令兼容?我意识到这不是一般问题,但更可能缺乏我的知识。但如果解决方案很简单,我将不胜感激。
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the TRACKERERRORSDLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// TRACKERERRORSDLL_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef TRACKERERRORSDLL_EXPORTS
#define TRACKERERRORSDLL_API __declspec(dllexport)
#define TRACKERERRORSDLL_VB __declspec(dllexport) __stdcall
#else
#define TRACKERERRORSDLL_API __declspec(dllimport)
#define TRACKERERRORSDLL_VB __declspec(dllimport) __stdcall
#endif
#include <string>
using namespace std;
bool TRACKERERRORSDLL_API GetTPIErrorDescription_wstring(long errorNumber,
basic_string<__wchar_t> & shortDescription,
basic_string<__wchar_t> & longDescription,
basic_string<__wchar_t> & solutionDescription,
bool & isAutoRecoverOnGreenState);
bool TRACKERERRORSDLL_API GetTPIErrorDescription_wstring(long errorNumber,
basic_string<unsigned short> & shortDescription,
basic_string<unsigned short> & longDescription,
basic_string<unsigned short> & solutionDescription,
bool & isAutoRecoverOnGreenState);
bool TRACKERERRORSDLL_API GetTPIErrorDescription_string(long errorNumber,
string & shortDescription,
string & longDescription,
string & solutionDescription,
bool & isAutoRecoverOnGreenState);
bool TRACKERERRORSDLL_API GetTPIErrorDescription_CString(long errorNumber,
CString & shortDescription,
CString & longDescription,
CString & solutionDescription,
bool & isAutoRecoverOnGreenState);
bool TRACKERERRORSDLL_VB GetTPIErrorDescription_VB(int errorNumber,
LPSTR* shortDescription,
LPSTR* longDescription,
LPSTR* solutionDescription,
bool* isAutoRecoverOnGreenState);
下载库(64位)的链接: https://docs.google.com/file/d/0BzzppV2CG8ZldzFRVzJUa252MHc/edit?usp=sharing
Matlab R2013a 64位
答案 0 :(得分:3)
您可以调用的唯一功能是GetTPIErrorDescription_VB
。所有其他人都使用您无法访问的C ++类。所以我建议您执行以下操作:
#include
和using
行。#ifdef
并将TRACKERERRORSDLL_VB
替换为__stdcall
。windows.h
或为Win32类型添加一些#define
语句。bool
类型。如果MATLAB无法识别,请将bool
替换为int
。此时,对loadlibrary
的调用应该有效,然后您只需要编写调用calllib
的代码。
生成的头文件可能看起来像这样:
#define LPSTR char*
__declspec(dllimport) bool __stdcall GetTPIErrorDescription_VB(
int errorNumber,
LPSTR* shortDescription,
LPSTR* longDescription,
LPSTR* solutionDescription,
bool* isAutoRecoverOnGreenState
);
最后,请注意LPSTR*
是一种相当令人惊讶的类型。它建议DLL将分配char*
C字符串,然后通过三个描述参数将它们返回给您。这提出了内存分配问题。谁会释放内存?它甚至需要被解除分配,还是静态的?需要通过查阅DLL的文档来解决这些问题。