Wrapping Visual C++ in C#

☆樱花仙子☆ 提交于 2019-12-04 14:39:57
Arnout

I think P/Invoke is really the most straightforward approach:

  • Create a DLL in unmanaged C++, containing all the functionality you need to do the injection.
  • In your C# code, declare some static extern methods, and use the DllImport attribute to point them to your C++ dll. For more details, see the link provided by arul in his answer.

Note that P/Invoke isn't limited to "windows API functions" — you can call functions exposed by any native DLL.

A potential downside of P/Invoke is that you will have to provide the signatures for your C++ functions, possibly specifying some less-than-obvious marshalling. In that case, you could consider constructing a COM server instead of a "plain" DLL, and using COM interop to call your code from C#.

You want to use P/Invoke, see MSDN Magazine.

If Pinvoking isn't what you want to do, then create a managed C++ application. Use native C++ to do the process injection stuff. Use managed c++ to create a .NET friendly interface to this native behaviour. This can then be called from C#.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!