Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using kernel32 in .Net

Tags:

c++

c#

interop

Question for the SO community. I have a C++ library with full source code and I am able to compile it in 32- and 64-bit mode. However, to call the code from .NET, I must choose either 32- or 64-bit, therefore forcing my application to be either 32- or 64-bit. I decided that I may have to live with that problem... but I stumbled across something that gives me hope. I noticed that I can reference "kernel32.dll" in an extern function and the program runs just fine in both 32- and 64-bit. Does anyone know how this is done?

Thanks!

like image 244
Terry Avatar asked Mar 25 '26 20:03

Terry


1 Answers

It's a feature of Windows on Windows 64 (WOW64): the File System Redirector

You can't really use it for your own libraries, because it's only for the System32 folder. (Do NOT even think about putting your DLLs in System32.)

Using SetDllDirectory might help, but I'm not sure.

like image 110
user541686 Avatar answered Mar 27 '26 09:03

user541686



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!