About very useful path functions (for information)

About very useful path functions (for information)

Postby Vladimir Grigoriev » Fri Feb 17, 2006 1:33 pm

Hi
Look at the reference
http://msdn.microsoft.com/library/defau ... h/path.asp

There are very interesting and useful functions. I think they should be realised in FiveWin.
As an example you can write and run the following C++ code (I used BCB 5.0 )

#include <windows.h>
#include <iostream.h>
#include <Shlwapi.h>
#include <conio.h>

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
using namespace std;

// Path_1 destination buffer.
char buffer_1[MAX_PATH] = "JustABufferToHoldTheCanonicalizedPathForAnExample";
char *lpStr1;
lpStr1 = buffer_1;

// Path_2 to be Canonicalized.
char buffer_2[ ] = "A:\\name_1\\.\\name_2\\..\\name_3";
char *lpStr2;
lpStr2 = buffer_2;

// Path_3 to be Canonicalized.
char buffer_3[ ] = "A:\\name_1\\..\\name_2\\.\\name_3";
char *lpStr3;
lpStr3 = buffer_3;

// Path_4 to be Canonicalized.
char buffer_4[ ] = "A:\\name_1\\name_2\\.\\name_3\\..\\name_4";
char *lpStr4;
lpStr4 = buffer_4;

// Path_5 to be Canonicalized.
char buffer_5[ ] = "A:\\name_1\\.\\name_2\\.\\name_3\\..\\name_4\\..";
char *lpStr5;
lpStr5 = buffer_5;

// Path_6 to be Canonicalized.
char buffer_6[ ] = "C:\\..";
char *lpStr6;
lpStr6 = buffer_6;

cout << "The un-canonicalized path 2 is : " << lpStr2
<< "\nThe return value is : "
<< PathCanonicalize(lpStr1,lpStr2)
<< "\nThe canonicalized path 1 is : " << lpStr1 << endl;

cout << "\nThe un-canonicalized path 3 is : " << lpStr3
<< "\nThe return value is : "
<< PathCanonicalize(lpStr1,lpStr3)
<< "\nThe canonicalized path 1 is : " << lpStr1 << endl;

cout << "\nThe un-canonicalized path 4 is : " << lpStr4
<< "\nThe return value is : "
<< PathCanonicalize(lpStr1,lpStr4)
<< "\nThe canonicalized path 1 is : " << lpStr1 << endl;

cout << "\nThe un-canonicalized path 5 is : " << lpStr5
<< "\nThe return value is : "
<< PathCanonicalize(lpStr1,lpStr5)
<< "\nThe canonicalized path 1 is : " << lpStr1 << endl;

cout << "\nThe un-canonicalized path 6 is : " << lpStr6
<< "\nThe return value is : "
<< PathCanonicalize(lpStr1,lpStr6)
<< "\nThe canonicalized path 1 is : " << lpStr1 << endl;


cout << "\nPress any key to exit...";
getch();

return EXIT_SUCCESS;
}

Vladimir Grigoriev
Vladimir Grigoriev
 
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow

Postby Antonio Linares » Mon Feb 20, 2006 7:31 am

Vlamidir,

This is the msdn entry:
http://msdn.microsoft.com/library/defau ... calize.asp

Its not difficult to be implemented
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Mon Feb 20, 2006 7:45 am

Here you have it working for FWH and Harbour/xharbour:
(its required to link echo lib\psdk\shlwapi.lib)
Code: Select all  Expand view  RUN
#include "Fivewin.ch"

function Main()

   local oDlg, cResult

   DEFINE DIALOG oDlg

   @ 2, 2 BUTTON "Test" ;
      ACTION ( PathCanonicalize( "A:\\name_1\\.\\name_2\\..\\name_3", @cResult ),;
               MsgInfo( cResult ) )
     
   ACTIVATE DIALOG oDlg ;
      CENTER

return nil

#pragma BEGINDUMP

#include <windows.h>
#include <Shlwapi.h>
#include <hbapi.h>

HB_FUNC( PATHCANONICALIZE ) // cInString, @cOutString --> lOk
{
   char * buffer[ MAX_PATH ];
   
   hb_retl( PathCanonicalize( buffer, hb_parc( 1 ) ) );
   hb_storc( buffer, 2 );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for CA-Clipper

Who is online

Users browsing this forum: No registered users and 2 guests

cron