题
我在c ++中不是那么好 但,.. 例如,我有这个
#define GETSomthing_API __declspec(dllexport)
extern GETSomthing_API int nGetSomthing;
.
和我想要这样的方法,如此
GETSomthing_API int GetSomthing(const char* szConfigPath, char *A, int B)
.
如何从c#中调用此?
旁边, 我认为我的问题是C ++侧的参数类型(const char *),它是c#中的相等类型!const char *
谢谢,
其他提示
有几种方法可以从C#调用本机代码。最简单的可能是使用P/Invoke
。
说你的功能就像:
extern "C" int nGetSomeThing(void);
.
并且它被编译为您的yourdllname.dll文件,可以使用p / Invoke以通过C#代码直接呼入非托管代码:
public static class interop
{
[DllImport("YourDllName.dll")]
static extern public int nGetSomeThing(void);
}
...
interop.nGetSomething() // call to the native function
.
参考: http://msdn.microsoft。COM / EN-US / LIBRARY / AA288468%28VS.71%29.aspx
如果您有很多具有复杂签名的函数,则应在C ++ / CLI中进行互操作图层。 参考: http://www.codeproject.com/articles/19354/quick-c-cli-learn-c-cli-in-less-than-10-minutes
我刚刚添加了__cplusplus检查并工作!
#ifdef __cplusplus
.
extern“c”{
ENDIF
GETSomthing_API char* GetAgentId(const char* szConfigPath, char *szA, int ASize);
.
ifdef __cplusplus
}
不隶属于 StackOverflow