我在非託管C++回調是這樣的:託管參數託管非託管回調?
typedef void (*ErrorCallback)(OutputLog& log, std::string& message);
它的使用(代碼簡化):
class OutputLog
{
private:
ErrorCallback _callback;
public:
void Error(std::string& message)
{
// print message to console/stream here
if (_callback)
{
_callback(*this, message);
}
}
};
在C++/CLI我創建了一個包裝類爲我的非託管OutputLog類。我定義的回調函數這樣:
public delegate void ErrorCallback(OutputLog^ log, String^ message);
所以我知道我可以通過Marshal::GetFunctionPointerForDelegate
獲取函數指針,但我怎麼的管理參數(OutputLog^ log
和String^ message
)轉換爲自己的非託管同行(OutputLog& log
和std::string& message
)?
完美!謝謝。 –