C++代码编译过程中错误应如何修正,求除错给出修正代码
【错误提示】
①[BCC32 Error] remac.cpp(140): E2034 Cannot convert 'unsigned short *' to 'const wchar_t *'
Full parser context
remac.cpp(96): parsing: void ResetAdapter(char *)
②[BCC32 Error] remac.cpp(140): E2342 Type mismatch in parameter '__s2' (wanted 'const wchar_t *', got 'unsigned short *')
Full parser context
remac.cpp(96): parsing: void ResetAdapter(char *)
③[BCC32 Warning] remac.cpp(155): W8004 'hr' is assigned a value that is never used
【源代码片段】
void ResetAdapter(char * AdapterName) { struct _GUID guid = {0xBA126AD1,0x2166,0x11D1,0}; memcpy(guid.Data4, "\xB1\xD0\x00\x80\x5F\xC1\x27\x0E", 8); unsigned short * buf = new unsigned short[strlen(AdapterName)+1]; void (__stdcall *NcFreeNetConProperties) (NETCON_PROPERTIES *); HMODULE NetShell_Dll = LoadLibrary("Netshell.dll"); if (!NetShell_Dll) { printf("无法加载Netshell.dll。\n"); return; } NcFreeNetConProperties = (void (__stdcall *)(struct tagNETCON_PROPERTIES *))GetProcAddress(NetShell_Dll, "NcFreeNetconProperties"); if (!NcFreeNetConProperties) { printf("无法加载需要的动态链接库函数!\n"); return; } for (unsigned int i = 0; i <= strlen(AdapterName); i++) { buf[i] = AdapterName[i]; } CoInitialize(0); INetConnectionManager * pNCM = NULL; HRESULT hr = ::CoCreateInstance(guid, NULL, CLSCTX_ALL, __uuidof(INetConnectionManager), (void**)&pNCM); if (!pNCM) printf("无法列出需要的对象!\n"); else { IEnumNetConnection * pENC; pNCM->EnumConnections(NCME_DEFAULT, &pENC); if (!pENC) { printf("无法枚举网络连接!\n"); } else { INetConnection * pNC; ULONG fetched; NETCON_PROPERTIES * pNCP; do { pENC->Next(1, &pNC, &fetched); if (fetched && pNC) { pNC->GetProperties(&pNCP); if (pNCP) { if (wcscmp(pNCP->pszwName, buf) == 0) { pNC->Disconnect(); pNC->Connect(); } NcFreeNetConProperties(pNCP); } } } while (fetched); pENC->Release(); } pNCM->Release(); } FreeLibrary(NetShell_Dll); CoUninitialize (); }