如何將函數(shù)指針從托管C ++(C ++ / CLI)傳遞給非托管方法?我讀了幾篇文章,例如MSDN上的這篇文章,但是它描述了兩種不同的程序集,而我只想要一種。這是我的代碼:1)標頭(MyInterop.ManagedCppLib.h):#pragma onceusing namespace System;namespace MyInterop { namespace ManagedCppLib { public ref class MyManagedClass { public: void DoSomething(); };}}2)CPP代碼(MyInterop.ManagedCppLib.cpp)#include "stdafx.h"#include "MyInterop.ManagedCppLib.h"#pragma unmanagedvoid UnmanagedMethod(int a, int b, void (*sum)(const int)){ int result = a + b; sum(result);}#pragma managedvoid MyInterop::ManagedCppLib::MyManagedClass::DoSomething(){ System::Console::WriteLine("hello from managed C++"); UnmanagedMethod(3, 7, /* ANY IDEA??? */);}我嘗試創(chuàng)建托管委托,然后嘗試使用Marshal::GetFunctionPointerForDelegatemethod,但無法編譯。
- 2 回答
- 0 關(guān)注
- 591 瀏覽
添加回答
舉報
0/150
提交
取消