0

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 internet 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.

14
  • 2
    VCRUNTIME140D.dll and UCRBASED.dll Means you have a dependency on the debug runtime. Whatever code you are using should be rebuilt to the Release configuration.
    – drescherjm
    Oct 7, 2020 at 14:56
  • I downloaded them from the internet This is actually a violation of the Visual Studio license. You should not download these files. These files are supposed to be supplied by Visual Studio that you installed and are used for debugging. You need to install a newer version of Visual Studio.
    – drescherjm
    Oct 7, 2020 at 14:57
  • 1
    The 140 is for Visual Studio 14.0, which is 2015.
    – Rup
    Oct 7, 2020 at 15:09
  • A static DLL is a contradiction in terms. DLLs should also always use the DLL version of the runtime so that it's shared with the app - having two different heaps for example will cause nothing but trouble. Oct 7, 2020 at 15:24
  • @drescherjm Removed the 3 dll's, compiled in Release mode I get Runtime error 53. With Process Monitor, I see "excel.exe" tries to load VCRUNTIME140D.DLL. I think I have the latest version of Visual Studio: I downloaded it on october 5 from the official Microsoft site.
    – Resca
    Oct 7, 2020 at 15:30

1 Answer 1

1

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!

1
  • I am glad you have got your solution and thanks for your sharing, I would appreciate it if you mark them as answer and this will be beneficial to other community. Oct 13, 2020 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.