Search code examples
c#ms-accessodbcms-jet-ace

What is the odbcjt32.dll real path, System32 or SysWOW64 to check it's parameters


I'm trying to create a ODBC connection programmatic, via registry.

When using Windows ODBC tool, I noticed that for ODBC 32, "Microsoft Access Driver (*.mdb)" is using odbcjt32.dll and the entry in registry would point to this location:

"Driver"="C:\\Windows\\system32\\odbcjt32.dll"

But when I search for the file, it exists, but is located in other folder:

C:\Windows\SysWOW64

I need to know why because:

  • I need to create connection from C#, I presume I should put the entry like ODBC tool does, to C:\Windows\system32
  • I want to check this DLL version from C#, so I should check C:\Windows\SysWOW64\odbcjt32.dll ??

There is a magic redirection for this DLL in Windows ?

Thanks for clarification,


Solution

  • See the super user question "System32 and SysWOW64 on Windows 7" for some background info on SysWoW64 and system32. So yes, there is a "magic redirection" on windows for 32 bit and 64 bit DLLs.

    The file odbcjt32.dll in C:\Windows\SysWOW64 is a 32 bit version. The path C:\Windows\system32\ is redirected to C:\Windows\SysWOW64\ for a 32 bit program. What is the current solution platfrom of your program? x86, x64 or Any CPU? I think it should be x86 so that it can use the 32 bit driver.

    Take a look at Environment.GetFolderPath method with Environment.SpecialFolder.SystemX86 so that you do not need to hardcode the path.

    Additional info on the magic redirection

    To see the bitness of a DLL you can use dumpbin.I use "odbc32.dll" in my examples below. Open the Developer Command Prompt of your Visual Studio version and execute the following command:

    dumpbin /headers c:\windows\syswow64\odbc32.dll
    

    The output will contain the following line:

    FILE HEADER VALUES
                 14C machine (x86)
    

    Now execute dumpbin for the DLL in the system32 directory:

    dumpbin /headers c:\windows\system32\odbc32.dll
    

    which outputs

    FILE HEADER VALUES
                8664 machine (x64)
    

    As you can see there is a x64 ("64 bit") and a x86 ("32 bit") version of the same DLL on the machine. Windows does the magic redirection depending on the bitness of the program that is running. A 64 bit program gets the DLL from C:\Windows\system32 and a 32 bit program gets it from C:\Windows\SysWoW64.