Total Commander Forum Index Total Commander
Forum - Public Discussion and Support
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WDX content plugin in C, need help
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Total Commander Forum Index -> Plugins and addons: devel.+support (English) Printable version
View previous topic :: View next topic  
Author Message
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Tue Nov 06, 2007 9:40 am    Post subject: WDX content plugin in C, need help Reply with quote

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
View user's profile Send private message
tbeu
Power Member
Power Member


Joined: 04 Jul 2003
Posts: 1021
Location: Germany

PostPosted: Tue Nov 06, 2007 10:39 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Tue Nov 06, 2007 11:40 am    Post subject: Reply with quote

Thanks for info. Is there any example in C (not C++) ? Embarassed
Back to top
View user's profile Send private message
ghisler(Author)
Site Admin
Site Admin


Joined: 04 Feb 2003
Posts: 24621
Location: Switzerland

PostPosted: Thu Nov 08, 2007 10:32 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Thu Nov 08, 2007 3:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
Flint
Power Member
Power Member


Joined: 27 Oct 2003
Posts: 2867
Location: Moscow, Russia

PostPosted: Thu Nov 08, 2007 3:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Thu Nov 08, 2007 3:25 pm    Post subject: Reply with quote

I got "this is not a valid plugin!" message when I try to load plugin Embarassed
Back to top
View user's profile Send private message
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Thu Nov 08, 2007 4:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
m^2
Power Member
Power Member


Joined: 12 Jul 2006
Posts: 1414
Location: Poland

PostPosted: Thu Nov 08, 2007 4:21 pm    Post subject: Reply with quote


_________________
Image: http://img201.imageshack.us/img201/2110/pcbsdec7.jpg
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Fri Nov 09, 2007 11:29 am    Post subject: Reply with quote

Back to top
View user's profile Send private message
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Fri Nov 09, 2007 12:06 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
ghisler(Author)
Site Admin
Site Admin


Joined: 04 Feb 2003
Posts: 24621
Location: Switzerland

PostPosted: Mon Nov 12, 2007 10:50 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Sun Nov 18, 2007 3:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
ghisler(Author)
Site Admin
Site Admin


Joined: 04 Feb 2003
Posts: 24621
Location: Switzerland

PostPosted: Mon Nov 19, 2007 10:57 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
bampkej
Junior Member
Junior Member


Joined: 06 Nov 2007
Posts: 11

PostPosted: Mon Nov 19, 2007 11:22 am    Post subject: Reply with quote

It works now in Visual C++ and .def file.
Thanks ! Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> Plugins and addons: devel.+support (English) All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Impressum: This site is maintained by Ghisler Software GmbH

Using phpBB © 2001-2005 phpBB Group