简体   繁体   English

将 32 位 dll 转换为 64 位

[英]Converting 32 bit dll to 64 bit

I had to switch to Office 64 bit (2019, Professional Plus).我不得不切换到 Office 64 位(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".我有大量的 VBA 脚本,其中大部分调用旧的 32 位 dll,用纯 C 语言编写并使用非常旧的 Developer Studio 97 编译。我设法用 Visual Studio 2019 将其重新编译为 C++ 8810378284650位和我遇到了 2 个问题:function MessageBox(和 MessageBoxA)被标记为“未定义”。 Workaround: I temporarily replaced them with OutputDebugStringA and the DLL compiles fine.解决方法:我暂时将它们替换为 OutputDebugStringA,DLL 编译正常。

Calling the function from VBA, it fails to load.从VBA调用function加载失败。 Thanks to ProcessorMonitor I found my dll tried to load VCRUNTIME140D.dll and UCRBASED.dll.感谢 ProcessorMonitor,我发现我的 dll 试图加载 VCRUNTIME140D.dll 和 UCRBASED.dll。 I downloaded them from the inte.net and I discovered I must place them in C:\Program Files\Microsoft Office\root\Office16.我从 inte.net 下载了它们,我发现我必须将它们放在 C:\Program Files\Microsoft Office\root\Office16 中。 But that was not enough.但这还不够。 VCRUNTIME140D.dll must be placed in C:\WINDOWS\SYSTEM32 too! VCRUNTIME140D.dll也必须放在C:\WINDOWS\SYSTEM32!

At that point, my DLL works fine as 64 bit dll.那时,我的 DLL 可以像 64 位 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.下一个惊喜是,重启后再次加载失败,原因是缺少VCRUNTIME140_APP.dll(请注意“140”后没有“D”): 下载并放置在C,\Program Files\Microsoft Office\root\Office16 . the DLL works fine as expected. DLL 按预期工作正常。

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.我试图将其编译为“静态”(“代码生成”->“运行时库”->“多线程”而不是“多线程 dll”)但出现错误:不支持 MSB8024 使用 static 版本的 C++ 运行时库。

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?我在某处读到 VCRUNTIME140 与 Visual Studio 2014 相关......很奇怪,但可能我也错过了那个版本的 some.obj 以便静态链接? 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.回到 MessageBox 问题,我尝试了一个简单的 c++ 64 位控制台应用程序,完全相同的 function 被接受并按预期工作,所以我猜是 header 文件中的一些 #ifdef 排除了 dll 中的声明。移动了 MessageBox 声明在我的 header 文件中,编译成功,但(正如我猜到的那样)出现了 MessageBox 的 linker“未解析的外部”。

At this points, my questions are: -Is it possible to create a 64 bit static .dll?此时,我的问题是:-是否可以创建 64 位static .dll? -Is it normal I have to download the above 3 dll's from the web and copy them in some directories? - 我必须从 web 下载以上 3 个 dll 并将它们复制到某些目录中是否正常 -It it possible to use the plain MessageBox (handle, text, caption, buttons) in a 64 bit dll? -是否可以在 64 位 dll 中使用普通 MessageBox(句柄、文本、标题、按钮)?

Thanks.谢谢。

Finally, thanks to rustyx's intuition, I discovered I was using a "Solution" suitable for "app" development.最后,感谢 rustyx 的直觉,我发现我使用的是适合“app”开发的“Solution”。 (The string _APP inside the called dll name indicated just that,) I managed to switch to "Desktop" solution. (被调用的 dll 名称中的字符串 _APP 表明了这一点,)我设法切换到“桌面”解决方案。 and now the dll's loaded are without the _APP suffix, The MessageBox function works fine.现在加载的 dll 没有 _APP 后缀,MessageBox function 工作正常。 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). VCRUNTIME140D.DLL(调试版)和 VCRUNTIME140.DLL(发布版)存在于我安装的安装中,它们Visual Studio 2019(以及 2015 和 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.最后,现在可以生成 static dll 在这种情况下,VCRUNTIME140.DLL(以及更多)不会在运行时加载,但相同的代码是静态链接的。 Dumpbin shows it. Dumpbin 展示了它。 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动态链接:USER32.dll VCRUNTIME140.dll api-ms-win-crt-filesystem-l1-1-0.dll api-ms-win-crt-stdio-l1-1-0.dll api-ms-heap-win-crt -1-0.dll API-MS-WIN-CRT-STRING-L1-1-1-0.dll API-MS-WIN-CRT-RUNTIME-L1-1-1-0.dll KERNEL32.88158888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888转

All problems solved!所有问题都解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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