SetTimer(NULL, 0, 1000, (TIMERPROC)Timer2Proc);
void CALLBACK NetSocket::Timer2Proc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
{
int err;
byte buf[32] = "";
char recvbuf[32] = "connect!!";
byte back[20] = {};
memset(buf, 0, sizeof(buf));
SetTimer(NULL, 1, 10000, SocketTimeOut);
err = Send(index, buf, back, 0, sizeof(buf));
KillTimer(NULL, 1);
}
SetTimer总是报错
成员函数看上去参数符合,其实不是,编译器会在函数最后加上隐含的 this 参数。
比如
void A::foo(int x)
其实是
void foo(int x, A* this)
所以和你的函数指针类型不匹配。
因为你没有把 Timer2Proc 设置为静态函数,类成员函数是不能作为参数传给SetTimer的。
实例:
NetSocket.h
#pragma once
class NetSocket
{
public:
NetSocket(void);
~NetSocket(void);
static void CALLBACK Timer2Proc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime);
};
NetSocket::NetSocket(void)
{
SetTimer(NULL, 0, 1000, (TIMERPROC)Timer2Proc);
}
NetSocket::~NetSocket(void)
{
}
void CALLBACK NetSocket::Timer2Proc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
{
//int err;
//byte buf[32] = "";
//char recvbuf[32] = "connect!!";
//byte back[20] = {};
//memset(buf, 0, sizeof(buf));
//SetTimer(NULL, 1, 10000, SocketTimeOut);
//err = Send(index, buf, back, 0, sizeof(buf));
//KillTimer(NULL, 1);
}