WDX content plugin in C, need help

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

Moderators: white, Hacker, petermad, Stefan2

bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

WDX content plugin in C, need help

Post by *bampkej »

Hi,
I'm new on forum.
I want to make some plugins for my work. Already got code in C, but now I have to make a WDX plugin (for custom column).

Could someone give me a simple example WDX plugin.
For example, plugin that
- accept only *.txt files (I have to implement ContentGetDetectString)
- return 1 if filename is a.txt
- custom column name is "test"

I've already read contentplugin.HLP help file.
I have to implement those functions
ContentGetSupportedField
ContentGetValue
and ContentGetDetectString (for .txt files).

But now I have no idea ... what do I have to do, a .dll file and rename it to wdx?
Please give me a push with simple example. I really want to make some plugins.

thanks a lot.

greetings!
User avatar
tbeu
Power Member
Power Member
Posts: 1336
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

Why not use the official sample?
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

Thanks for info. Is there any example in C (not C++) ? :oops:
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48093
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Just try the sample, it's mostly plain C, not C++. Only minor modifications should be necessary to compile it with an ANSI C compiler.
Author of Total Commander
https://www.ghisler.com
bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

Thanks.
I've successfully compiled sample. How do I get WDX file ? I've compiled it as shared library, got DLL, what should I do then, rename it to wdx or ?
User avatar
Flint
Power Member
Power Member
Posts: 3487
Joined: 2003-10-27, 09:25 UTC
Location: Antalya, Turkey
Contact:

Post by *Flint »

bampkej wrote:what should I do then, rename it to wdx or ?
Yes, just rename it. Or you can even leave it as DLL, it does not matter.
Flint's Homepage: Full TC Russification Package, VirtualDisk, NTFS Links, NoClose Replacer, and other stuff!
 
Using TC 10.52 / Win10 x64
bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

I got "this is not a valid plugin!" message when I try to load plugin :oops:
bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

If I test dll with WDXtest plugin, I get
Plugin libtcfilesys.dll loaded.
Plugin does not imlement ContentGetDetectString()
Plugin does not imlement ContentPluginUnloading()
Plugin does not imlement ContentSetDefaultParams()
Error: plugin does not imlement mandatory ContentGetSupportedField()

how do I propertly export those functions ?
User avatar
m^2
Power Member
Power Member
Posts: 1413
Joined: 2006-07-12, 10:02 UTC
Location: Poland
Contact:

Post by *m^2 »

bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

Thanks for info.
Still same problem :(
I've used:

Code: Select all

__declspec(dllexport) int __stdcall ContentGetValue(char* FileName,int FieldIndex,int UnitIndex,void* FieldValue,int maxlen,int flags)
Here is source:
http://www.megafileupload.com/en/file/22812/wdx-src-zip.html

Thanks[/code]
bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

I probably need to export it with that .def file.
I've checked exported functions with fileinfo plugin and they have strange names, like
_Z15ContentGetValuePciiPvii@24

Can someone tell me how to add that .def file to linker.
I'm using eclipse + MinGW

Only setting that I've found under MinGW C++ linker - Shared Library options is :
Def file name (-Wl,--output-def=):

but if I set that one, it generates def file and not use it as input for renaming functions.

help please :)
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48093
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

A quick Google search brought me here:
http://www.geocities.com/yongweiwu/stdcall.htm

CL can accept a DEF file on the command line, and it simply passes the file name to LINK. E.g.,

cl /LD testdll.obj testdll.def

will become

link /out:testdll.dll /dll /implib:testdll.lib /def:testdll.def testdll.obj
Author of Total Commander
https://www.ghisler.com
bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

Thanks for help.
Now I've exported functions with extern "C" __declspec(dllexport).
I can load plugin without error, but when I want to add custom column, total commander crashes (Access violation at address ...).

Here is simple code that I've used:

Code: Select all

#include "stdafx.h"
#include "contentplug.h"

#define fieldcount 1
char* fieldnames[fieldcount]={"title"};
int fieldtypes[fieldcount]={ft_string};

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{        
	return TRUE;
}

char* strlcpy(char* p,const char* p2,int maxlen)
{
    if ((int)strlen(p2)>=maxlen) {
        strncpy(p,p2,maxlen);
        p[maxlen]=0;
    } else
        strcpy(p,p2);
    return p;
}

extern "C" __declspec(dllexport) int ContentGetSupportedField(int FieldIndex,char* FieldName,char* Units,int maxlen)
{
	if (FieldIndex<0 || FieldIndex>=fieldcount)
		return ft_nomorefields;
	strlcpy(FieldName,fieldnames[FieldIndex],maxlen-1);	
	return fieldtypes[FieldIndex];
}

extern "C" __declspec(dllexport) int ContentGetValue(char* FileName,int FieldIndex,int UnitIndex,void* FieldValue,int maxlen,int flags)
{
	switch (FieldIndex) {
	case 0:  			
		strlcpy((char*)FieldValue,(char*)"test",maxlen-1);		
		break;
	default:
		return ft_nosuchfield;
	}
	return fieldtypes[FieldIndex];
}

Any idea what is wrong ?

Thanks
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48093
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

To my knowledge, these functions will have the C calling convention: The caller must remove the variables from the stack. Windows and Total Commander, however, use the stdcall calling convention, where the function itself removes the local variables from the stack. Therefore you get a crash.

Try defining the functions like this:

int __stdcall ContentGetSupportedField(int FieldIndex,char* FieldName,char* Units,int maxlen)

Then create a file yourproject.def which contains a list of all the exported functions:

EXPORTS
ContentGetSupportedField
Author of Total Commander
https://www.ghisler.com
bampkej
Junior Member
Junior Member
Posts: 11
Joined: 2007-11-06, 15:30 UTC

Post by *bampkej »

It works now in Visual C++ and .def file.
Thanks ! :D
Post Reply