我用 C++ 編寫了一個動態(tài)鏈接庫并正確導出它,以便 Go 能夠使用 Win32 API 獲取適配器信息。但是當我在 Go 中調用它的函數(shù)時,它拋出“找不到指定的過程”錯誤。我是 Go 的新手,所以我不知道如何解決它。有人可以幫助我嗎?這是有關我的環(huán)境的一些信息:平臺:windows 10 x64CXX 編譯器:visual c++ 15.3去版本:go1.11.2 windows/amd64這是我的代碼:#include "stdafx.h"#include <WinSock2.h>#include <iphlpapi.h>#include <iostream>#include <vector>using namespace std;__declspec(dllexport) const char *get_default_gateway();vector <string> default_gateway;const char *get_default_gateway(){ PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO(); PIP_ADAPTER_INFO info_p; unsigned long stSize = sizeof(IP_ADAPTER_INFO); int nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize); info_p = pIpAdapterInfo; if (ERROR_BUFFER_OVERFLOW == nRel) { delete pIpAdapterInfo; pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[stSize]; nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize); info_p = pIpAdapterInfo; } if (ERROR_SUCCESS == nRel) { while (info_p) { IP_ADDR_STRING *pIpAddrString = &(info_p->IpAddressList); do { string gateway_tmp = info_p->GatewayList.IpAddress.String; if (gateway_tmp != "0.0.0.0") { default_gateway.push_back(info_p->GatewayList.IpAddress.String); } pIpAddrString = pIpAddrString->Next; } while (pIpAddrString); info_p = info_p->Next; } } if (pIpAdapterInfo) { delete []pIpAdapterInfo; } const char *gateway = default_gateway.at(0).c_str(); return gateway;}
1 回答

犯罪嫌疑人X
TA貢獻2080條經(jīng)驗 獲得超4個贊
很有可能您遇到了 C++ 編譯器對導出函數(shù)的名稱應用名稱修改的影響,因此它實際上并沒有按照您在庫的導出表中期望的方式命名。您可以使用 objdump 或古老的depends.exe
.?最簡單的方法是將導出函數(shù)的聲明包裝到extern "C" { ... }
—復習一下。
- 1 回答
- 0 關注
- 211 瀏覽
添加回答
舉報
0/150
提交
取消