如何使用VSCode在GOARCH = 386中的64位GO项目上使用32位DLL

I have installed VSCode and GO extension with defaults packages. My project need to load a 32-bit DLL. When I launch project with F5, I get error 193 on syscall.LoadLibrary().

I found on internet that error usually occurs when someone try to load a 32-bit DLL on a 64-bit arch.

I think if I debug with GOARCH=386 I would be able to load the DLL. But every time that I try to execute with GOARCH=386 I get error on VSCode saying that this architecture is unsupported.

Need help.

The issue is because you are trying to load 32bit dll on 64bit architecture. Use 64 bit dll file. Along with that Install using 64bit dll for golang.

Just if you try to install delve from 32bit dll on 64 bit OS. This is also mentioned in the issues on github:

https://github.com/derekparker/delve/issues/20

VS Code complains if you want to run 32bit dll on 64 bit OS. If you have 32bit dll for golang Uninstall that and install from 64bit dll again.

(I assume that a 64-bit DLL is out of reach)

64-bit process cannot load a 32-bit module into its process space, and a 32-bit processes cannot load a 64-bit module into its process space. The only way that communication can happen between 32-bit and 64-bit modules is through inter-process communication (IPC). Microsoft recommends that you use inter-process COM to use 32 bit code with a 64 bit application. Here's an article explaining the process. It's ugly.

If it's OK on your end, build your project to X86 platform (32-bit). In that way ehlapi32.dll is compatible & problem solved. Your 32-bit software is still supported on a 64-bit platform as 32-bit processes can be executed on 64-bit Windows operating system.

--

  • I familiar with C++ & not at all with GO. I have no idea how (or if at all) that technique can be implemented in GO.