Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call win32 dll in windows 7

Tags:

c#

dllimport

From within a C# application(Visual Studio 2008) i am calling a win32 dll using DllImport. Everything works fine in Windows XP. However when i use the same exe and dll in Windows 7, the win32 dll fails to get loaded. Do i need to write any extra code to invoke a win32 dll from Windows 7 ?

like image 259
user968341 Avatar asked Feb 03 '26 15:02

user968341


1 Answers

Before building the C# program, make sure that in Visual studio Configuration Manager you choose "x86" and not "any CPU" as the platform. If any CPU is selected, your C# application runs as a 64bit process in Windows 7 and tries to load the 32-bit win32 dll in to the 64-bit process which would fail as explained here and here.

like image 130
Martin Avatar answered Feb 05 '26 05:02

Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!