[英]How do I call a function in a C++ Dll from C# that has void* callback and object parameter
[英]How do I call a C++ DLL from C#/WPF project
我有以下代码:
namespace WPFMuskTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[DllImport
("myDll.DLL",
EntryPoint = "?Func1@FUllNameCopiedFromDependancyWalker",
CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl
)
]
public static extern System.IntPtr Func1(out System.IntPtr handle, int type, out DateTime date);
public MainWindow()
{
InitializeComponent();
//
//
//
}
private void button1_Click(object sender, RoutedEventArgs e)
{
System.IntPtr MainParam;
int thetype = 1
DateTime date;
System.IntPtr res = GetFxIRMoveForDate(out MainParam, thetype _til, out date);
}
}
}
该exe与所调用的DLL位于同一路径中,并且该函数肯定存在于DLL中(在DependacyWalker中进行了验证),但我不断收到错误消息:
调用的函数原型为:
类__declspec(dllexport)OUR_DATE_TYPE {....}
typedef unsigned long TYPE; typedef DATE_TYPE OUR_DATE_TYPE;
namespace1
{
namespace2
{
void func1(MyClass &myclass, const TYPE& type, const DATE_TYPE& date);
}
}
类型为“ System.AccessViolationException”的未处理异常
谁能告诉我为什么?
默认情况下,c ++不使用cdecl
调用约定,而是使用stdcall
。 您可能会更成功地将ac包装器写入c ++ api并调用它,因为C具有定义明确的ABI 。
编辑:再次查看您的代码,我怀疑DateTime
是否与您在C ++中使用的日期类型相同。 例如,如果尺寸错误,则可能会发生此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.