我有下面的代碼:如何調用C從C#/ ++ DLL的WPF項目
namespace WPFMuskTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[DllImport
("myDll.DLL",
EntryPoint = "[email protected]",
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#DLL中看到該方法的簽名,才能知道是否正確鍵入了DllImport。 –
添加了C++原型 - 我猜這就是你的意思? – Stefan
你能提供'TYPE'和'DATE_TYPE'的宏定義嗎? – Dai