Author Topic: Creating a 32-bit DLL  (Read 4024 times)

Offline alfredfvj

  • Single posting newcomer
  • *
  • Posts: 7
Creating a 32-bit DLL
« on: July 27, 2023, 07:27:20 am »
Hello,

We are currently converting a "legacy" system written in VFP to C++. The system is very large i.e., it covers almost all corporate applications. As such, we want to implement the migration to C++ on a piecemeal approach starting with the general functions using DLL.

Using CodeBlocks wizard, I created a minimal DLL project and compiled it without encountering any errors. However, when I tried to use it in VFP under Windows 11, I got an error "Cannot load 32-bit DLL".

I assumed that the DLL generated was 64-bit so I went back to CB, edited the compiler settings and checked Target x86 (32bit) [-m32] and rebuilt the project. This time, I encountered 21 errors all of which were related to ld.exe not able to find library files. So, I edited the linker settings to include the lib files (ex. libuser32.a, libmingw32.a, libmoldname.a, etc.) including the full path. I also included in the Seach Directories the folder where these files are located. When I built the project, I still got the same "cannot find..." errors. 

I tried searching Google for answers but found no solution that worked. Any help will be greatly appreciated.

Thanks.


Online stahta01

  • Lives here!
  • ****
  • Posts: 7682
    • My Best Post
Re: Creating a 32-bit DLL
« Reply #1 on: July 27, 2023, 02:48:58 pm »
To build an 32 bit DLL you need to use an 32 bit compiler toolchain.
Using an 64 bit compiler toolchain in theory would work; but, the of people who tried that and succeeded is zero in the post I have read on this website.

Note: The above is for MinGW GCC Windows based toolchains; I hear on Linux the problem might not exist.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1635
Re: Creating a 32-bit DLL
« Reply #2 on: July 27, 2023, 02:51:56 pm »
The -m32 and -m64 flags are effective only if you have a multilib toolchain, something infrequent. You should install a toolchain targetting the desired bitness and do not use -m at all. You can have two toolchains, one for 32-bit targets and another for the 64-bit ones.

Offline nenin

  • Almost regular
  • **
  • Posts: 228
Re: Creating a 32-bit DLL
« Reply #3 on: July 28, 2023, 01:41:19 pm »
Hello,

We are currently converting a "legacy" system written in VFP to C++.****
I tried searching Google for answers but found no solution that worked. Any help will be greatly appreciated.

Thanks.
I do it like this. I have 3 actual used mingw, 32b, 32b/XP (this is different story) and 64b.
I have two separated folders for 32 nd 64 bit versions.
In each folder I have separated subfolders for  each versions.
So, it looks like this:
c:\mingw32\winlibs09.3_XP\
c:\mingw32\winlibs12.1\
In dedicated compiler folder I have subfolder for third-party libraries, which I built by myself.
I switch path to required compiler when I need exact version.
Also in C::B I prepared separated profile for each compiler, so it looks like that (example for XP, "comp.png"). And assign this profile to project ("prof.png").
Compilers might be from WinLibs or Nixman. You can use gdb64 for both 32 and 64 versions, if GDB fresh enough (v11, i guess).
« Last Edit: July 28, 2023, 01:45:48 pm by nenin »