| View previous topic :: View next topic |
| Author |
Message |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Tue Nov 06, 2007 9:40 am Post subject: WDX content plugin in C, need help |
|
|
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! |
|
| Back to top |
|
 |
tbeu Power Member


Joined: 04 Jul 2003 Posts: 1021 Location: Germany
|
Posted: Tue Nov 06, 2007 10:39 am Post subject: |
|
|
Why not use the official sample? _________________ My plugins: Autodesk 3ds Max Preview, Blat Mailer, ImageMetaData (JPG Comment/EXIF/IPTC/XMP) , MATLAB MAT-file Viewer, SolidWorks Preview and more |
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Tue Nov 06, 2007 11:40 am Post subject: |
|
|
Thanks for info. Is there any example in C (not C++) ?  |
|
| Back to top |
|
 |
ghisler(Author) Site Admin


Joined: 04 Feb 2003 Posts: 24621 Location: Switzerland
|
Posted: Thu Nov 08, 2007 10:32 am Post subject: |
|
|
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
http://www.ghisler.com |
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Thu Nov 08, 2007 3:10 pm Post subject: |
|
|
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 ? |
|
| Back to top |
|
 |
Flint Power Member


Joined: 27 Oct 2003 Posts: 2867 Location: Moscow, Russia
|
Posted: Thu Nov 08, 2007 3:24 pm Post subject: |
|
|
| 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, other stuff!
Using TC 8.01 / Win7 x64 SP1 |
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Thu Nov 08, 2007 3:25 pm Post subject: |
|
|
I got "this is not a valid plugin!" message when I try to load plugin  |
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Thu Nov 08, 2007 4:08 pm Post subject: |
|
|
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 ? |
|
| Back to top |
|
 |
m^2 Power Member


Joined: 12 Jul 2006 Posts: 1414 Location: Poland
|
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Fri Nov 09, 2007 11:29 am Post subject: |
|
|
|
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Fri Nov 09, 2007 12:06 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
ghisler(Author) Site Admin


Joined: 04 Feb 2003 Posts: 24621 Location: Switzerland
|
Posted: Mon Nov 12, 2007 10:50 am Post subject: |
|
|
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
http://www.ghisler.com |
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Sun Nov 18, 2007 3:59 pm Post subject: |
|
|
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: |
#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 |
|
| Back to top |
|
 |
ghisler(Author) Site Admin


Joined: 04 Feb 2003 Posts: 24621 Location: Switzerland
|
Posted: Mon Nov 19, 2007 10:57 am Post subject: |
|
|
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
http://www.ghisler.com |
|
| Back to top |
|
 |
bampkej Junior Member

Joined: 06 Nov 2007 Posts: 11
|
Posted: Mon Nov 19, 2007 11:22 am Post subject: |
|
|
It works now in Visual C++ and .def file.
Thanks !  |
|
| Back to top |
|
 |
|