亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

c ++ / cli將(托管)委托傳遞給非托管代碼

c ++ / cli將(托管)委托傳遞給非托管代碼

C++
躍然一笑 2019-10-29 13:02:29
如何將函數指針從托管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 關注
  • 592 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號