views:

864

answers:

3

I need to do some process injection using C++ but I would prefer to use C# for everything other than the low level stuff. I have heard about "function wrapping" and "marshaling" and have done quite a bit of google searching and have found bits of information here and there but I am still really lacking.

Things I have read in order of usefulness;
http://msdn.microsoft.com/en-us/library/ms235281(VS.80).aspx
http://www.drdobbs.com/cpp/184401742
http://geeklit.blogspot.com/2006/08/calling-c-lib-from-c.html

How can I wrap all the lower level stuff (native C++) in C# so I can easily command those functions in a language I am more comfortable with, C#?

Any information on the topic is much appreciated.

+2  A: 

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

arul
The only thing is that I am not trying to call any windows API function. I want to inject into a 3rd party process, and call certain functions in that process using asm/etc via native C functions that I can call from say C#. Maybe I am misunderstanding the article however. Thanks.
Marcus Cicero
+1  A: 

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#.

OJ
Any guides or examples you could point me to? Thanks!
Marcus Cicero
+3  A: 
Arnout
Thank you for the clarification.
Marcus Cicero