BUG: WNetGetUniversalName Fails Under Windows 95

ID: Q131416


The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows 95


SYMPTOMS

The WNetGetUniversalName function takes a drive-based path for a network resource and obtains a data structure that contains a more universal form of the name. This function always fails with error 1200 when called from a 32-bit application running under Windows 95.


RESOLUTION

The functionality provided by WNetGetUniversalName can be implemented using the Win32 network enumeration functions WNetOpenEnum and WNetEnumResource. Here is an example of how to use these functions to implement similar functionality:


   #include <windows.h>
   #include <stdio.h>

   // Function Name:  GetUniversalName
   // 
   // Parameters:     szUniv  - Contains the UNC equivalent of szDrive
   //                           upon completion.
   // 
   //                 szDrive - Contains a drive-based path.
   // 
   // Return value:   TRUE if successful; otherwise, FALSE.
   // 
   // Comments:       This function assumes that szDrive contains a
   //                 valid drive-based path.
   // 
   //                 For simplicity, this code assumes szUniv points
   //                 to a buffer large enough to accommodate the UNC
   //                 equivalent of szDrive.

   BOOL GetUniversalName( char szUniv[], char szDrive[] )
   {

      // Get the local drive letter.
      char chLocal = toupper( szDrive[0] );

      // Cursory validation.
      if ( chLocal < 'A' || chLocal > 'Z' )
         return FALSE;

      if ( szDrive[1] != ':' || szDrive[2] != '\\' )
         return FALSE;

      HANDLE hEnum;
      DWORD dwResult = WNetOpenEnum( RESOURCE_CONNECTED, RESOURCETYPE_DISK,
                                     0, NULL, &hEnum );

      if ( dwResult != NO_ERROR )
         return FALSE;

      // Request all available entries.
      const int    c_cEntries   = 0xFFFFFFFF;
      // Start with a reasonable buffer size.
      DWORD        cbBuffer     = 50 * sizeof( NETRESOURCE );
      NETRESOURCE *pNetResource = (NETRESOURCE*) malloc( cbBuffer );

      BOOL fResult = FALSE;

      while ( TRUE )
      {
         DWORD dwSize   = cbBuffer,
               cEntries = c_cEntries;

         dwResult = WNetEnumResource( hEnum, &cEntries, pNetResource,
                                      &dwSize );

         if ( dwResult == ERROR_MORE_DATA )
         {
            // The buffer was too small, enlarge.
            cbBuffer = dwSize;
            pNetResource = (NETRESOURCE*) realloc(pNetResource, cbBuffer);
            continue;
         }

         if ( dwResult != NO_ERROR )
            goto done;

         // Search for the specified drive letter.
         for ( int i = 0; i < (int) cEntries; i++ )
            if ( pNetResource[i].lpLocalName &&
                 chLocal == toupper(pNetResource[i].lpLocalName[0]) )
            {
               // Match.
               fResult = TRUE;

               // Build a UNC name.
               strcpy( szUniv, pNetResource[i].lpRemoteName );
               strcat( szUniv, szDrive + 2 );
               _strupr( szUniv );
               goto done;
            }
      }

   done:

      // Clean up.
      WNetCloseEnum( hEnum );
      free( pNetResource );

      return fResult;

   } 
An alternative workaround to using WNetOpenEnum and WNetEnumResource is to use WnetGetConnection, which, when provided the drive letter of a shared drive, returns the UNC name that is mapped to that drive.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

Additional query words:

Keywords : kbnetwork kbAPI kbSDKPlatform kbWinOS95 kbWNet kbDSupport kbCodeSam kbGrpNet
Version : winnt:
Platform : winnt
Issue type : kbbug


Last Reviewed: July 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.