BUG: WNetGetUniversalName Fails Under Windows 95

Last reviewed: November 7, 1997
Article ID: Q131416
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK), version 4.0

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:
      // cleanup
      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, will return the UNC name that is mapped to that drive.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional query words: Win95
Keywords : NtwkWinnet kbcode kbnetwork
Platform : Win95
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 7, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.