Mingw GCC for LSplugin help needed

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
stuntstein
Junior Member
Junior Member
Posts: 14
Joined: 2006-12-01, 07:44 UTC
Contact:

Mingw GCC for LSplugin help needed

Post by *stuntstein »

Hi forum,

I'm trying to convert a lister plugin from borland compiler to gcc in order to be able to build x64 version. My borland version doesn't do x64.

So to make it simple I took the lister plugin sample from Ghisler and created a project with Codeblocks.

Things seem to work. Both x32 and x64 plugin starts, but ... when I do a text search the x32 version crash with below information. The x64 version works fine.

Here are the compiler and linker output.
g++.exe -fpermissive -DBUILD_DLL -O2 -W -fexceptions -m32 -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL -DLISTPLUG_EXPORTS -g -c C:\_\listplugsample\cunicode.cpp -o Release\cunicode.o
g++.exe -fpermissive -DBUILD_DLL -O2 -W -fexceptions -m32 -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL -DLISTPLUG_EXPORTS -g -c C:\_\listplugsample\listplug.cpp -o Release\listplug.o
g++.exe -fpermissive -DBUILD_DLL -O2 -W -fexceptions -m32 -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL -DLISTPLUG_EXPORTS -g -c C:\_\listplugsample\StdAfx.cpp -o Release\StdAfx.o
g++.exe -shared -Wl,--output-def=Release\liblistplug -Wl,--out-implib=Release\liblistplug -Wl,--dll Release\cunicode.o Release\listplug.o Release\StdAfx.o -o Release\listplug.wlx -static -static-libgcc -static-libstdc++ -shared -m32 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
Output file is Release\listplug.wlx with size 143.00 KB


To me it looks like a NULL pointer issue but I can't seem to catch it in the plugin code and think it is something in totalcmd.exe.

Any good ideas?
Why does x64 works and not x32? It is because my PC is a x64?

Thanks.

PS: I had to rename __stdcall to __cdecl to export the functions correctly.
PSS: Have tried multiple mingw gcc versions, both x32 only and x32&x64 but all give the same result.


Crash output:
---------------------------
Total Commander 8.51RC2
---------------------------
Access violation at address 00000000. Read of address 00000000.
Access violation at address 00000000. Read of address 00000000
Windows 7 SP1 6.1 (Build 7601)

Please report this error to the Author, with a description
of what you were doing when this error occurred!

Windows exception: C0000005
Stack trace:
00000000
62B9D7 6447A3 63E32A 63C3B9 449033 446589
4484F6 >42590C 447A9B 42590C 42AFC8 42B064
70550F
Raw:
62B9D7 6447A3 447A09 42590C 44886F 446589
4487C5 4487C5 43785A 447AEE 447A9B 42590C
700A2C 56B6A9 6F8CFC 418F99 6F8CFC 6E0ADF
70274B 6FB298 6E0C68 6E0C68 447A09 42590C
44886F 428179 446589 4487C5 4275E8 447B66
4484F6 448519 42590C 447A9B 42590C 69006A
69006A 6E0073 447A09 42590C 4275E8 4464BF
63E32A 704D0D 61627B 471077 70262F 6FB836
6B6C9A 619956 610072 6F004B 447A09 42590C
44886F 446589 4487C5 446589 43785A 447AEE

Press Ctrl+C to copy this report!
Continue execution?
---------------------------
Yes No
---------------------------
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50475
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

PS: I had to rename __stdcall to __cdecl to export the functions correctly.
That's the problem here - you MUST export them as __stdcall! To avoid the name mangling, you also need to add the "listplug.def" file to the sources, and make sure that all exported functions are listed there.
Author of Total Commander
https://www.ghisler.com
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 »

I can confirm this on TDM-GCC.
You definitely need __stdcall!

If you don't want or can use an export list, because it's quite a mess with command-line GCC to tell which functions to export,
prefix extern "C" to all TC functions (all with __stdcall and, quite important, to DllMain !).
So you could get sth. like:

Code: Select all

extern "C" int __stdcall ListSearchDialog(HWND ListWin,int FindNext) {...}
Now the one thing still missing are the correct names, because you probably now have exports like ListLoad@12 etc.
To get this right and removing the "@xx", add the switch -Wl,--kill-at to your linker command,
so it becomes e.g. :

Code: Select all

g++.exe -Wl,--kill-at -shared -Wl,--output-def=Release\liblistplug -Wl,--out-implib=Release\liblistplug -Wl,--dll Release\cunicode.o Release\listplug.o Release\StdAfx.o -o Release\listplug.wlx -static -static-libgcc -static-libstdc++ -shared -m32 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
BTW, why are ListSearchText() and ListSearchDialog() using _stdcall instead of __stdcall? (missing underscore) On purpose?
stuntstein
Junior Member
Junior Member
Posts: 14
Joined: 2006-12-01, 07:44 UTC
Contact:

Post by *stuntstein »

I got it working :-)
Now text search doesn't crash!

I changed the header to:
#define DECLSPEC __declspec(dllexport) __stdcall
#ifdef __cplusplus
extern "C" {
#endif
void DECLSPEC ListCloseWindow(HWND ListWin);
...
...
#ifdef __cplusplus
}
#endif

If I don't use dllexport I get a bunch of unwanted exported functions. With dllexport everything is nice and clean.
Yes I also added -Wl,--kill-at to the linker options.

Thanks to Ghisler and the forum for great support.
Post Reply