-2

After several hours Google'ing, I have no the solution to this problem.

I have developed a DLL in unmanaged C++. I have placed that DLL in SysWOW64 folder since this is a 64 bit computer.

On the other hand, I have a Winforms application developed in C# that imports the functions contained in the DLL. I use DllImport("name.dll"), however a System.DllNotFoundException is thrown.

The whole solution is configured for x64 platform.

If I place the DLL in the executable directory, it works.

I want the DLL to be in the system folder because of simplicity in development. I am developing this project in 2 different computers (a desktop PC and my notebook). The PC has 32 bits platform, while the notebook is 64 bits, with different folders.

To syncronize projects in both computers I use subversion repository. I can, obviously write a Post Build event to copy the DLL from the C++ project folder to the output folder of the main executable, but I will need to change the Post build command every time I move from notebook to PC or vice versa.

Any idea why the DLL is not found in the System folder? and most importantly, is there a way to solve it?

Thanks Jaime

jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • 3
    If the solution is compiled to x64, you have to put the dll to `%SystemRoot%\System32` folder. `%SystemRoot%\SysWOW64\` is used by 32 bit applications (x86) – Wernfried Domscheit May 05 '15 at 18:29
  • When I use %SystemRoot%\System32, system actually copies the file to SysWOW64... it seems that internally, if the system is x64, the system translates automatically System32 to SysWOW64, as a sort of alias, maybe – jstuardo May 05 '15 at 19:33

1 Answers1

4

The whole solution is configured for x64 platform.

The SysWOW64 is actually the 32 bit system directory. For a 32 bit program, the file system redirector will redirect system32 to SysWOW64.

  • For a 32 bit process, the system directory is SysWOW64.
  • For a 64 bit process, the system directory is system32.

This would explain the problem you face.

For what it is worth, you really should not be modifying the system directory. It belongs to the system and applications should not modify it.

Jim G.
  • 15,141
  • 22
  • 103
  • 166
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490