- FIXED_INFO* pFixedInfo = NULL;
- ULONG OutBufLen = 0;
- DWORD result;
-
- result = GetNetworkParams(NULL, &OutBufLen);
- if (result == ERROR_BUFFER_OVERFLOW) {
- pFixedInfo = (FIXED_INFO*)malloc(OutBufLen);
- if (!pFixedInfo) {
- _tprintf(_T("ERROR: failed to allocate 0x%08lX bytes of memory\n"), OutBufLen);
- return;
- }
- } else {
- _tprintf(_T("ERROR: GetNetworkParams() failed to report required buffer size.\n"));
- return;
- }
-
- result = GetNetworkParams(pFixedInfo, &OutBufLen);
- if (result == ERROR_SUCCESS) {
- IP_ADDR_STRING* pIPAddr;
-
- _tprintf(_T("\tHostName. . . . . . . . . . . : %s\n"), pFixedInfo->HostName);
- _tprintf(_T("\tDomainName. . . . . . . . . . : %s\n"), pFixedInfo->DomainName);
-
- _tprintf(_T("\tDNS Servers . . . . . . . . . : %s\n"), pFixedInfo->DnsServerList.IpAddress.String);
- pIPAddr = pFixedInfo->DnsServerList.Next;
- while (pIPAddr) {
- _tprintf(_T("\t\t\t\t : %s\n"), pIPAddr->IpAddress.String);
- pIPAddr = pIPAddr->Next;
- }
-
- _tprintf(_T("\tNodeType. . . . . . . . . . . : %d (%s)\n"), pFixedInfo->NodeType, GetNodeTypeName(pFixedInfo->NodeType));
- _tprintf(_T("\tScopeId . . . . . . . . . . . : %s\n"), pFixedInfo->ScopeId);
- _tprintf(_T("\tEnableRouting . . . . . . . . : %s\n"), pFixedInfo->EnableRouting ? _T("yes") : _T("no"));
- _tprintf(_T("\tEnableProxy . . . . . . . . . : %s\n"), pFixedInfo->EnableProxy ? _T("yes") : _T("no"));
- _tprintf(_T("\tEnableDns . . . . . . . . . . : %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
- _tprintf(_T("\n"));
-/*
- _tprintf(_T("\n"),);
- _tprintf(_T("GetNetworkParams() returned with %d\n"), pIfTable->NumAdapters);
-
- _tprintf(_T("\tConnection specific DNS suffix: %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
-*/
- } else {
- switch (result) {
- case ERROR_BUFFER_OVERFLOW:
- _tprintf(_T("The buffer size indicated by the pOutBufLen parameter is too small to hold the adapter information. The pOutBufLen parameter points to the required size\n"));
- break;
- case ERROR_INVALID_PARAMETER:
- _tprintf(_T("The pOutBufLen parameter is NULL, or the calling process does not have read/write access to the memory pointed to by pOutBufLen, or the calling process does not have write access to the memory pointed to by the pAdapterInfo parameter\n"));
- break;
- case ERROR_NO_DATA:
- _tprintf(_T("No adapter information exists for the local computer\n"));
- break;
- case ERROR_NOT_SUPPORTED:
- _tprintf(_T("This function is not supported on the operating system in use on the local system\n"));
- break;
- default:
- _tprintf(_T("0x%08lX - Use FormatMessage to obtain the message string for the returned error\n"), result);
- break;
- }
+ LPVOID lpMsgBuf;
+ DWORD RetVal;
+
+ if ((RetVal = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ ErrorCode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+ (LPTSTR) &lpMsgBuf,
+ 0,
+ NULL ))) {
+ _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
+
+ LocalFree(lpMsgBuf);
+ /* return number of TCHAR's stored in output buffer
+ * excluding '\0' - as FormatMessage does*/
+ return RetVal;