Supporting Unicode in a Plugin

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
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Supporting Unicode in a Plugin

Post by *djorge »

Hi,
I've tried to modify the fs_samplePlugin sources to unicode by:
- define UNICODE and _UNICODE
- modified all the char to _TCHAR
- modified all non unicode functions like strcpy, strcmp to its unicode compliant version
- modied both fsplugin.h and fsplugin.cpp exported function that are called by TC

It compiles fine and TC can load the unicode plugin, but it displays an "A" as the plugin name in the Network Neighborhood and plugin doesn't work.

I know that TC is not unicode, and it calls the fs exported functions with non unicode variables and that's what it is confusing me.

Is it possible to make an UNICODE plugin or not?
I am using VS2005.
______________________
David Jorge
Personal License #117854
poiuytr
Senior Member
Senior Member
Posts: 243
Joined: 2003-02-23, 17:33 UTC

Post by *poiuytr »

You can build a unicode plugin which uses unicode internally, but you can't use TC API with wchar_t's. Just leave TC API as is (without TCHAR wrappers).
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

Ok. Thanks. I will try it today.

But if i define UNICODE and _UNICODE, won't the compiler complain with the TC API char* parameter and all the non unicode functions?
______________________
David Jorge
Personal License #117854
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

If i leave TC API as is, then all the string function used to manipulate this variable must be non unicode and VS complains about that due to the UNICODE and _UNICODE definitions. Is really this what you meant?
______________________
David Jorge
Personal License #117854
VadiMGP
Power Member
Power Member
Posts: 672
Joined: 2003-04-05, 12:11 UTC
Location: Israel

Post by *VadiMGP »

2djorge
You have first to convert all needed strings from char to wchar. For example with MultiByteToWideChar function.
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

VadiMGP wrote:2djorge
You have first to convert all needed strings from char to wchar. For example with MultiByteToWideChar function.
Thanks.
:shock:
I thought it would be a litle easier.
I think i will stick with non unicode for now....
______________________
David Jorge
Personal License #117854
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

I'm trying to convert the FS sample plugin to UNICODE. I'm only using the mandatory interface.

The interface remains the same (non unicode), and i'm using the new ATL7.0 conversion objects. I can't get the plugin to work with my changes.

The FNC loop returns: "A","B","C","D","E" instead of "A:","B:","C:","D:","E:".

I'm using the folowing conversion objects CA2T, CW2A, CW2A.
The code is exactly the same of the sample plugin, with minor changes to support unicode. I conver unicode strings back to ansi whenever i have to return something to TC.
What i'm doing wrong?

Code: Select all

HANDLE __stdcall FsFindFirst(char* Path,WIN32_FIND_DATA *FindData)
{
   CA2T TPath(Path);

   TCHAR buf[MAX_PATH];
   pLastFindStuct lf;


    memset(FindData,0,sizeof(WIN32_FIND_DATA));
   if (_tcscmp(TPath,_T("\\"))==0) {
      FindData->dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY;
      FindData->ftLastWriteTime.dwHighDateTime=0xFFFFFFFF;
      FindData->ftLastWriteTime.dwLowDateTime=0xFFFFFFFE;
      lf=(pLastFindStuct)malloc(sizeof(tLastFindStuct));
      CW2A aPath(TPath);
      strcpy(lf->Path,aPath);
      lf->searchhandle=INVALID_HANDLE_VALUE;
      TCHAR ch='A';
      _tcscpy(buf,_T("A:\\"));
      while (GetDriveType(buf)==DRIVE_NO_ROOT_DIR && ch<'Z'+1) {
         ch++;
         buf[0]=ch;
      }
      buf[2]=0;
      if (ch<='Z') {
         CW2A aBuf(buf);
         strcpy(lf->LastFoundName,aBuf);
         _tcscpy(FindData->cFileName,buf);
         return (HANDLE)lf;
      } else {
         free(lf);
         return INVALID_HANDLE_VALUE;
      }
   } else {
      _tcscpy(buf,TPath+pluginrootlen);
      _tcscat(buf,_T("\\*.*"));
      HANDLE hdnl=FindFirstFile(buf,FindData);
      if (hdnl==INVALID_HANDLE_VALUE)
         return INVALID_HANDLE_VALUE;
      else {
         lf=(pLastFindStuct)malloc(sizeof(tLastFindStuct));
         CW2A aBuf(buf);
         strcpy(lf->Path,aBuf);
         lf->searchhandle=hdnl;
         return (HANDLE)lf;
      }
   }
   return INVALID_HANDLE_VALUE;
}

BOOL __stdcall FsFindNext(HANDLE Hdl,WIN32_FIND_DATA *FindData)
{
   TCHAR buf[MAX_PATH];
   pLastFindStuct lf;

   if ((int)Hdl==1)
      return false;

   lf=(pLastFindStuct)Hdl;
   if (lf->searchhandle==INVALID_HANDLE_VALUE) {   // drive list!
      TCHAR ch=lf->LastFoundName[0];
      _tcscpy(buf,_T("A:\\"));
      buf[0]=ch+1;
      while (GetDriveType(buf)==DRIVE_NO_ROOT_DIR && ch<'Z'+1) {
         ch++;
         buf[0]=ch;
      }
      buf[2]=0;
      if (ch<='Z') {
         CW2A aBuf(buf);
         strcpy(lf->LastFoundName,aBuf);
         _tcscpy(FindData->cFileName,buf);
         return true;
      } else {
         return false;
      }

   } else {
      lf=(pLastFindStuct)Hdl;
      BOOL ret = FindNextFile(lf->searchhandle,FindData);
      return ret;
   }
   return false;
}
______________________
David Jorge
Personal License #117854
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50421
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

The name is returned in WIN32_FIND_DATA. Total Commander expects a WIN32_FIND_DATAA, while you assume a WIN32_FIND_DATAW. You need to copy the data from the Unicode struct to an Ansi struct and convert the file name accordingly too.
Author of Total Commander
https://www.ghisler.com
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

2ghisler(Author)
Thanks. You were right. It works now.
______________________
David Jorge
Personal License #117854
Post Reply