Thursday, July 9, 2009

How call windows api from c#?

please explain :


using windows api within c#








-------THANKS--------

How call windows api from c#?
There are two types of windows api.


1- Managed


2- Unmanaged





If your trying to access C++ code from C# then you need to lookup Interops. At work I had to do this, it is quite messy. What you have to is create an Interop class using the .NET interopability feature which is called P/Invoke.





What you are doing exactly is creating a wrapper to be used in C#. I believe you have the header files (.h) and you need to Call each function within that header file to C#. It is called interoping. In C# it is called DLLImport.





It is quite an extensive subject.


Every define you need to transform it to C#


Every struct you need to transform it to C#


Every macro you need to define it in C#


Every method you need dllimport it in C#


Every callback you need to delegate it in C#


ALL datatypes should be converted to the C# equivalent (C++/CLI)





Inorder to use DLLImport you have to use Unmanaged DLL's, managed dlls can be simply added as reference to the project so you dont need to interop it.





Please take a look at these links, they will help you tremendously.


http://quickstart.developerfusion.co.uk/...


http://mono-project.com/Interop_with_Nat...


http://msdn2.microsoft.com/en-us/library...


http://www.pinvoke.net/





Take a time to read it and understand how to do it. If you need help, I could help you since It is quite a stressing subject hehe.





Good Luck!
Reply:You will need to use DLLImport in order to register these methods and then they are used like any other method.


No comments:

Post a Comment