Tôi không gặp vấn đề gì với Winsock kể từ khi tôi bắt đầu sử dụng nó. Tôi dường như không thể khởi tạo Winsock để cứu mạng tôi. Tôi không yêu cầu bất cứ ai viết toàn bộ chương trình (Như tôi biết làm thế nào gây phiền nhiễu đó là) Tôi chỉ cần giúp đỡ với Winsock. Tôi đã thử một số trình biên dịch và luôn có lỗi lạ.Lập trình Winsock
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main
1>C:\Users\Rory\ProjectX\ProjectX\Debug\ProjectX.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Users\Rory\ProjectX\ProjectX\ProjectX\Debug\BuildLog.htm"
1>ProjectX - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Đây là mã của tôi:
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <winsock2.h>
int iReqWinsockVer = 2;
using namespace std;
int main()
{
cout<<"Initializing Winsock 2...\n";
// WINSOCK INITIALIZATION
WSADATA wsaData;
if (WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0) {
// Check if major version is at least iReqWinsockVer
if (LOBYTE(wsaData.wVersion) >= iReqWinsockVer) {
// Network stuff here
}
else {
// Required version not available
}
// Cleanup winsock
if (WSACleanup()!=0) {
// cleanup failed
}
}
else {
// startup failed
}
// END WINSOCK INITIALIZATION
system("PAUSE");
}
+1 chính xác - nó không phải là một vấn đề khởi tạo Winsock từ xa, chỉ là một trình liên kết xây dựng tiêu chuẩn "chưa được giải quyết". –