【发布时间】:2012-09-24 15:26:23
【问题描述】:
我有以下代码:
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 无符号长类型; typedef DATE_TYPE OUR_DATE_TYPE;
namespace1
{
namespace2
{
void func1(MyClass &myclass, const TYPE& type, const DATE_TYPE& date);
}
}
“System.AccessViolationException”类型的未处理异常
谁能告诉我为什么?
【问题讨论】:
-
我们确实需要查看 C# DLL 中方法的签名,以了解您是否正确键入了 DllImport。
-
添加了 C++ 原型 - 我猜这就是你的意思?
-
能否提供
TYPE和DATE_TYPE的宏定义? -
MyClass myclass和IntPtr handle可能不对应,因为myclass没有作为指针传递。 -
抱歉,已经更正了一个错字 - 请再看看!