我有一个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...

}

最佳答案

Dependency Walker可以向您展示从DLL中有效导出了哪些功能。您将能够看到您的fnmain是否存在,或者是否是_fnmain,或者名称中具有C++装饰。

10-04 10:36