Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GetShortPathName
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
GetShortPathName
Divers
Thread ID:
00387670
Message ID:
00387670
Vues:
51
I'm trying to build my knowledge of utilizing Win32API and with it a library of Win32API calls. Is it better to put them in a class library or a procedure file or what? Here's one I put in a program file with my own procedure taken from the API section here on UT
* Win32API.PRG

PROCEDURE myGetShortPathName
LPARAMETERS tcLongPathName

* Accepts a path as a parameter.  
* If the path is invalid or missing then GetFile gets one

LOCAL lcLongFile, lcBuffer, lnBufferSize, lnShortPathLen, lcShortPath

* Validate parameter
IF EMPTY(tcLongPathName) OR ;
   VARTYPE(tcLongPathName) <> 'C' OR ;
   !FILE(tcLongPathName)
      lcLongFile = GETFILE()
     IF !FILE(lcLongFile)
        * user cancelled or again entered invalid stuff
        RETURN
     ENDIF
ELSE
   * the path is valid
   lcLongFile = tcLongPathName
ENDIF

DECLARE INTEGER GetShortPathName IN Win32API ;
   STRING  @cLongPath, ;
   STRING  @cShortPathBuff, ;
   INTEGER nBuffSize

* Example in Visual FoxPro 
* lcLongFile     = "c:\program files\somefolder\my file name.doc"
* lcBuffer       = SPACE(511)
* lnBufferSize   = 511
* lnShortPathLen = GetShortPathName(lcLongFile, @lcBuffer, @lnBufferSize)
* lcShortPath    = LEFT(lcBuffer, lnBufferSize)

* Above should be  LEFT(lcBuffer, lnShortPathLen)

lcBuffer = SPACE(511)
* should this be set to the maximum length allowed for a long path name?
lnBufferSize = 511
lnShortPathLen = GetShortPathName(lcLongFile, @lcBuffer, @lnBufferSize)
lcShortPath = LEFT(lcBuffer, lnShortPathLen)
RETURN lcShortPath
Am I on the right track? Thanks to Erik Moore for the code in the API section and Mike Helland for the cool mhHTML. Congrats too Mike and any other new MVP!
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform