Skip to content

Commit

Permalink
Fixed the bug that Npcap loopback adapter renaming fails in Win10 RTM…
Browse files Browse the repository at this point in the history
… Chinese version.
  • Loading branch information
hsluoyz committed Dec 29, 2015
1 parent 9f443b5 commit 6bb5fbe
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions packetWin7/NPFInstall/NPFInstall/LoopbackRename2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,52 @@ wstring getNpcapLoopbackAdapterName()
return L"";
}

wstring ANSIToUnicode(const string& str)
{
int len = 0;
len = str.length();
int unicodeLen = ::MultiByteToWideChar(CP_ACP,
0,
str.c_str(),
-1,
NULL,
0);
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen + 1];
memset(pUnicode, 0, (unicodeLen + 1)*sizeof(wchar_t));
::MultiByteToWideChar(CP_ACP,
0,
str.c_str(),
-1,
(LPWSTR) pUnicode,
unicodeLen);
wstring rt;
rt = (wchar_t*) pUnicode;
delete pUnicode;
return rt;
}

wstring executeCommand(wchar_t* cmd)
{
char buffer[128];
string tmp = "";
wstring result;

FILE* pipe = _wpopen(cmd, L"r");
if (!pipe)
{
return L"";
}

wchar_t buffer[128];
wstring result = L"";
while (!feof(pipe))
{
if (fgetws(buffer, 128, pipe) != NULL)
result += buffer;
if (fgets(buffer, 128, pipe) != NULL)
tmp += buffer;
}
_pclose(pipe);

result = ANSIToUnicode(tmp);

return result;
}

Expand Down

0 comments on commit 6bb5fbe

Please sign in to comment.