【发布时间】:2012-02-22 10:03:04
【问题描述】:
我有一个 C# 应用程序,我试图从它向 C++ 函数发送一个参数。但是,我收到了错误(主题中提到)
C# 应用程序:
static class SegmentationFunctions
{
[DllImport("MyApplication.dll", EntryPoint = "fnmain", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern int fnmain(string search);
}
}
public partial class MainWindow:Window
{
public MainWindow()
{
InitializeComponent();
string search = "test string here";
int scommand = SegmentationFunctions.fnmain(search);
}
C++ 文件.h
extern "C" QUERYSEGMENTATION_API int fnmain(char query[MAX_Q_LEN]);
C++ 文件 .cpp
extern "C" QUERYSEGMENTATION_API int fnmain(char searchc[MAX_LEN_Q])
{
do something...
}
【问题讨论】:
-
QUERYSEGMENTATION_API 明确在您的 C++ 项目中定义为 __declspec(dllexport),当您在 Dependency Walker 中打开 MyApplication.dll 时,您能否看到导出的函数(depends.exe 是Visual Studio 工具,以防您不确定)?
标签: c# c++ visual-c++