BUG: WNetGetUniversalName Fails Under Windows 95Last reviewed: November 7, 1997Article ID: Q131416 |
The information in this article applies to:
SYMPTOMSThe 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.
RESOLUTIONThe 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.
STATUSMicrosoft 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |