如何将函数指针从托管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??? */);}我尝试创建托管委托,然后尝试使用Marshal::GetFunctionPointerForDelegatemethod,但无法编译。
2 回答
- 2 回答
- 0 关注
- 556 浏览
添加回答
举报
0/150
提交
取消