0
我正在将我在Borland编写的voip应用程序移植到Mingw,所以我知道代码有效。我使用命令行gcc -lws2_32 -mwindows voipapp.c -o voipapp
和不断收到错误消息将WSAAsyncSelect与Mingw链接 - undefined参考
未定义的引用“WSAAsyncSelect @ 16””。
这似乎是正确的定位libws2_32.a
因为没有错误消息上来告诉我,否则。任何想法,什么都可以错了,我有最新版本的MinGW安装感谢的一个
我的代码如下:?!
#include <windows.h>
#include <winsock2.h>
#define __MT__
#include <mmreg.h>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <process.h>
#define WM_SOCKETREAD (WM_USER + 1)
SOCKET ListenSocket;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR szCmdLine, int iCmdShow) {
static char szAppName[] = "voip";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
RegisterClassEx(&wndclass);
hwnd = CreateWindow(szAppName, "VOIP prototype",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
WSAAsyncSelect(ListenSocket, hwnd, WM_SOCKETREAD, FD_READ|FD_CLOSE);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}