DelphiFAQ Home Search:

Retrieve the UNC version of a file's name

 

comments1 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

The function needed for this is WNetGetUniversalName. The online help (win32.hlp) says about this function's arguments:


  • lpBuffer
    Points to a buffer that receives the type of data structure specified by the dwInfoLevel parameter. This data structure has a pointer to a string buffer:

    typedef struct _UNIVERSAL_NAME_INFO { /* uni */ LPTSTR lpUniversalName; } UNIVERSAL_NAME_INFO;

    The UNIVERSAL_NAME_INFO structure contains a pointer to a Universal Naming Convention (UNC) name string.


  • As I found out, this is wrong. In fact, it contains a pointer to itself followed by the string buffer.
    Since the pointer takes 4 Bytes, the string starts at Buffer[4].

    This piece of code works:

    var
      cFile,
      Buffer : array [0..450] of char;
      Size   : DWord;
      ret    : integer;
      FileName : string;
    ..
      Size := sizeof(Buffer);
      ret := WNetGetUniversalName(StrPCopy(cFile, FileName),
               UNIVERSAL_NAME_INFO_LEVEL, @Buffer, Size);
      if ret = NO_ERROR then
        Result := PChar(@Buffer[4])
      else
        Result := FileName;
    

    Comments:

    2006-04-21, 07:20:07
    anonymous from Turkey  
    rating



    Keywords:

     

     

    NEW: Optional: Register   Login
    Email address (not necessary):

    Rate as
    Hide my email when showing my comment.
    Please notify me once a day about new comments on this topic.
    Please provide a valid email address if you select this option, or post under a registered account.
     

    Show city and country
    Show country only
    Hide my location
    You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
    Please type in the code:

    Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
    The owner of this web site reserves the right to delete such material.

    photo Add a picture: