WCX plugin in C++Builder

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

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Athari
Junior Member
Junior Member
Posts: 24
Joined: 2004-01-08, 15:12 UTC

WCX plugin in C++Builder

Post by *Athari »

The only function TC calls in my WCX plugin is DllMain. For example, when I compile the following file and register it as packer plugin, TC just shows an error message, which in English sounds like 'Unknown format or an error in the archive "filename"!' Other functions are never called (I don't see any message boxes). In fact TC ataches and detaches 2 times. (There previosly was ShowMessage in DllMain showing fwdreason.) I've deleted almost everything from the source just to show the problem. To the point, lister plugins work this way and I haven't any problems with them.
--- Unit1.cpp ---
#include <vcl.h>
#include <windows.h>
#pragma hdrstop

typedef struct {
char ArcName[260];
char FileName[260];
int Flags;
int PackSize;
int UnpSize;
int HostOS;
int FileCRC;
int FileTime;
int UnpVer;
int Method;
int FileAttr;
char* CmtBuf;
int CmtBufSize;
int CmtSize;
int CmtState;
} tHeaderData;

typedef struct {
char* ArcName;
int OpenMode;
int OpenResult;
char* CmtBuf;
int CmtBufSize;
int CmtSize;
int CmtState;
} tOpenArchiveData;

#pragma argsused
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}

extern "C" __declspec(dllexport) HANDLE __stdcall OpenArchive (tOpenArchiveData *ArchiveData)
{
ShowMessage("open arc\n");
return (void*)1;
}

extern "C" __declspec(dllexport) int __stdcall ReadHeader (HANDLE hArcData, tHeaderData *HeaderData)
{
ShowMessage("read head");
return 10;
}

extern "C" __declspec(dllexport) int __stdcall ProcessFile (HANDLE hArcData, int Operation, char *DestPath, char *DestName)
{
ShowMessage("proc file");
return 24;
}

extern "C" __declspec(dllexport) int __stdcall CloseArchive (HANDLE hArcData)
{
ShowMessage("close arc");
return 1;
}
--- end ---
Sorry for my bad English, my native language is C++ :)
gigaman
Member
Member
Posts: 131
Joined: 2003-02-14, 11:28 UTC

Post by *gigaman »

Just a guess - aren't the functions exported as decorated? I.e. isn't OpenArchive actually exported as _OpenArchive@4 (which TC doesn't find, of course)?

I don't know C++ Builder, but in VC I had to use the following .def file to turn the function names into what they really should be:

LIBRARY PlugingName

EXPORTS

CloseArchive=_CloseArchive@4
GetPackerCaps=_GetPackerCaps@0
OpenArchive=_OpenArchive@4
ProcessFile=_ProcessFile@16
ReadHeader=_ReadHeader@8
SetChangeVolProc=_SetChangeVolProc@8
SetProcessDataProc=_SetProcessDataProc@8
CanYouHandleThisFile=_CanYouHandleThisFile@4
User avatar
André Martin
Senior Member
Senior Member
Posts: 245
Joined: 2003-02-05, 15:46 UTC
Location: Dresden, Germany

Post by *André Martin »

Just declare your functions this way:

extern "C" HANDLE __export WINAPI OpenArchive(tOpenArchiveData *ArchiveData)

It works perfectly with BCB5 and there is no need for a *.def file...
Browse the web with the HTTP SmartBrowserPlugin
Check your mails with the POP3/SMTP EmailPlugin!
User avatar
Athari
Junior Member
Junior Member
Posts: 24
Joined: 2004-01-08, 15:12 UTC

Post by *Athari »

It still doesn't work :( When I export functions like "extern "C" __export WINAPI HANDLE __stdcall OpenArchive (tOpenArchiveData *ArchiveData)" it works the same way as worked before: TC detects that it is plugin (so it finds all needed functions), but when I try to open associated archive, it ataches and detaches two times and then shows an error message. Both QuickView and TC viewer plugin shows that functions are exported with correct names, without any "_" or "@", so the problem isn't with function names.

Andre Martin, could you give me working source, please? Just project with all function declarations would be enough.
gigaman
Member
Member
Posts: 131
Joined: 2003-02-14, 11:28 UTC

Post by *gigaman »

You have to implement the functions SetChangeVolProc and SetProcessDataProc (even though the SDK doesn't say so).
User avatar
André Martin
Senior Member
Senior Member
Posts: 245
Joined: 2003-02-05, 15:46 UTC
Location: Dresden, Germany

Post by *André Martin »

2Athari
I need your email address in order to mail you the working sample...
User avatar
Athari
Junior Member
Junior Member
Posts: 24
Joined: 2004-01-08, 15:12 UTC

Post by *Athari »

Andre Martin, thanks, but I don't need help anymore. Gigaman was right about those 'Proc' functions.
Excuse me for my bad English, my native language is C++
lotfib
Junior Member
Junior Member
Posts: 3
Joined: 2004-09-05, 10:01 UTC

examples for BCB 6

Post by *lotfib »

Hi

Could someone, give me a starting example in BCB 6 or so

Thanks in advance
Post Reply