@@ -383,8 +383,81 @@ PrintError(
383383 _In_ DWORD dwErrId ,
384384 ...)
385385{
386- DPRINT1 ("PrintError()\n" );
387- return 1 ;
386+ PWSTR pszInBuffer = NULL , pszOutBuffer = NULL ;
387+ DWORD dwLength = 0 ;
388+ va_list ap ;
389+
390+ DPRINT ("PrintError(%p %lu ...)\n" , hModule , dwErrId );
391+
392+ va_start (ap , dwErrId );
393+
394+ pszOutBuffer = HeapAlloc (GetProcessHeap (), 0 , HUGE_BUFFER_SIZE * sizeof (WCHAR ));
395+ if (pszOutBuffer == NULL )
396+ goto done ;
397+
398+ if (hModule )
399+ {
400+ pszInBuffer = HeapAlloc (GetProcessHeap (), 0 , HUGE_BUFFER_SIZE * sizeof (WCHAR ));
401+ if (pszInBuffer == NULL )
402+ goto done ;
403+
404+ dwLength = LoadStringW (hModule , dwErrId , pszInBuffer , HUGE_BUFFER_SIZE );
405+ if (dwLength == 0 )
406+ goto done ;
407+
408+ dwLength = FormatMessageW (FORMAT_MESSAGE_FROM_STRING ,
409+ pszInBuffer ,
410+ 0 ,
411+ 0 ,
412+ pszOutBuffer ,
413+ HUGE_BUFFER_SIZE ,
414+ & ap );
415+ }
416+ else
417+ {
418+ if ((dwErrId > NETSH_ERROR_BASE ) && (dwErrId < NETSH_ERROR_END ))
419+ {
420+ pszInBuffer = HeapAlloc (GetProcessHeap (), 0 , HUGE_BUFFER_SIZE * sizeof (WCHAR ));
421+ if (pszInBuffer == NULL )
422+ goto done ;
423+
424+ dwLength = LoadStringW (GetModuleHandle (NULL ), dwErrId , pszInBuffer , HUGE_BUFFER_SIZE );
425+ if (dwLength == 0 )
426+ goto done ;
427+
428+ dwLength = FormatMessageW (FORMAT_MESSAGE_FROM_STRING ,
429+ pszInBuffer ,
430+ 0 ,
431+ 0L ,
432+ pszOutBuffer ,
433+ HUGE_BUFFER_SIZE ,
434+ & ap );
435+ }
436+ else
437+ {
438+ dwLength = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM ,
439+ NULL ,
440+ dwErrId ,
441+ MAKELANGID (LANG_NEUTRAL , SUBLANG_DEFAULT ),
442+ pszOutBuffer ,
443+ HUGE_BUFFER_SIZE ,
444+ & ap );
445+ }
446+ }
447+
448+ va_end (ap );
449+
450+ if (dwLength > 0 )
451+ ConPuts (StdOut , pszOutBuffer );
452+
453+ done :
454+ if (pszOutBuffer )
455+ HeapFree (GetProcessHeap (), 0 , pszOutBuffer );
456+
457+ if (pszInBuffer )
458+ HeapFree (GetProcessHeap (), 0 , pszInBuffer );
459+
460+ return dwLength ;
388461}
389462
390463DWORD
0 commit comments