Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
4.71/5 (3 votes)
See more:
this is my first time doing a server and client application that need me to call a c++ method from a c# client. how exactly can i do it? Please show some sample code regarding this matter thank you. ;-)
Posted

If the C++ code is COM-Callable, then you just need to add a reference to the DLL. It basically creates the typelib for you. I believe (but I'm not sure) that the namespace becomes the dll library name.
 
Share this answer
 
If it has a managed wrapper, then you can add it as reference to your c# project. Then create an object and use it.

If it does not have it, then use DllImport attribute.

If your C++ dll uses ordinal numbers or extern "C" to export methods, then you can use Win32 APIs to call the methods.
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900