开发者

Possible to write C# DLL (plugin) for a C++ application?

I'd like to write a plugin (DLL) for a C++ application but I'd like to use C#. Is this possible? I don't have access to the C++ code so I can't modify it.

From what I've gathered, the C++ (host) application just makes calls to different functions.

Here's a C++ sample plugin function:

void On_Start(HINSTANCE hInstance, HWND hWnd, BOOL bLogSet, int nDLLID, char * szHotKey)

H开发者_如何学JAVAow would this translate to a C# DLL that can be loaded from this C++ application?


Not directly, but you could write a shim in C++/CLI that exports the native function then delegates the actual implementation to a C# assembly.

Keep in mind, however, that this is probably a bad idea -- only one version of the CLR may run in a given process, so if someone else writes a managed plugin for the C++ application that targets a different version of the CLR than your plugin does, then fatal runtime errors will result.


This project Creates dll exports for static methods in classes. This might be a cleaner solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜