简体   繁体   中英

Converting 32 bit dll to 64 bit

I had to switch to Office 64 bit (2019, Professional Plus). I have a large number of VBA scripts and most of them make calls to an old 32 bit dll written in plain C language and compiled with the very old Developer Studio 97. I managed to recompile it with Visual Studio 2019 as a C++ dll at 64 bits and I faced 2 problems: the function MessageBox (and MessageBoxA) is flagged as "undefined". Workaround: I temporarily replaced them with OutputDebugStringA and the DLL compiles fine.

Calling the function from VBA, it fails to load. Thanks to ProcessorMonitor I found my dll tried to load VCRUNTIME140D.dll and UCRBASED.dll. I downloaded them from the inte.net and I discovered I must place them in C:\Program Files\Microsoft Office\root\Office16. But that was not enough. VCRUNTIME140D.dll must be placed in C:\WINDOWS\SYSTEM32 too!

At that point, my DLL works fine as 64 bit dll.

Next surprise was that, after a reboot, it once again failed to load due to missing VCRUNTIME140_APP.dll (please note no "D" after "140"): Downloaded and placed in C,\Program Files\Microsoft Office\root\Office16. the DLL works fine as expected.

I tried to compile it as "static" ('Code Generation' -> 'runtime library' -> 'multithreaded' instead 'multithreaded dll') but I got the error: MSB8024 Using static version of the C++ runtime library is not supported.

Somewhere I read that VCRUNTIME140 is related to Visual Studio 2014... strange, but may be I miss some.obj from that version too in order to statically link? Why do I need elements from an older system?

Back to the MessageBox problem, I tried a simple c++ 64 bit console application and the exact same function is accepted and works as expected, so I guessed was some #ifdef in the header files that excludes the declaration in a dll. Moved the MessageBox declarations in my header file, the compilation is successful, but (as I could guess) a linker "unresolved external" for MessageBox shows up.

At this points, my questions are: -Is it possible to create a 64 bit static .dll? -Is it normal I have to download the above 3 dll's from the web and copy them in some directories? -It it possible to use the plain MessageBox (handle, text, caption, buttons) in a 64 bit dll?

Thanks.

Finally, thanks to rustyx's intuition, I discovered I was using a "Solution" suitable for "app" development. (The string _APP inside the called dll name indicated just that,) I managed to switch to "Desktop" solution. and now the dll's loaded are without the _APP suffix, The MessageBox function works fine. without the need of any particular settings in libraries.

VCRUNTIME140D.DLL (debug version) and VCRUNTIME140.DLL (release version) are present in my installation installed while they are part of Visual Studio 2019 (as well as 2015 and 2017).

Finally, it is now possible to generate a static dll in this case, VCRUNTIME140.DLL (and many more) is not loaded at runtime but the same code is statically linked. Dumpbin shows it. Dynamic linking: USER32.dll VCRUNTIME140.dll api-ms-win-crt-filesystem-l1-1-0.dll api-ms-win-crt-stdio-l1-1-0.dll api-ms-win-crt-heap-l1-1-0.dll api-ms-win-crt-string-l1-1-0.dll api-ms-win-crt-runtime-l1-1-0.dll KERNEL32.dll Static linking: USER32.dll KERNEL32.dll

All problems solved!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM