English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

please explain :
using windows api within c#


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

2006-06-24 05:27:01 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

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/QuickStart/howto/doc/Interop/PInvoke_Simple.aspx
http://mono-project.com/Interop_with_Native_Libraries
http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute_members.aspx
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!

2006-06-24 16:32:52 · answer #1 · answered by ? 6 · 3 0

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

2006-06-24 20:28:25 · answer #2 · answered by MC Nat 2 · 0 0

fedest.com, questions and answers