Skip to content

C# Using Unmanaged or Win32 API In Your Code

C# Using Unmanaged Or Win32 API In Your Code

As good as C# is in developing extensive solutions quickly, there are much limitations to it and there may come a time when you need to use unmanaged code.

When using the Win32 API in your code, you will inevitably end up looking at various function signatures from documentation online. However, certain types that exist in C does not exist in C# and so an equivalent will be needed. This where pinvoke comes in handy as they provide the converted function signature from C to C# for you.

You must also bear in mind the differences in the size of various types on different platform (x86 vs x64). For example, an IntPtr is 4 bytes long on a x86 platform, while 8 bytes long a x64 platform. This is important especially if you wish for your code to be usable on both platforms.

 

Enjoyed the content ? Share it with your friends !
Published inDevelopmentProgramming

Be First to Comment

Leave a Reply

Your email address will not be published.