我正在尝试将结构传递给我的线程 CreateThread()
,这是我的结构:
struct Secure
{
int UID;
LPVOID MainClass;
};
这是我打电话的方式CreateThread()
Secure m_Secure = {Room->g_User[PlayerNumber].UID,this};
CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)SecureThread,&m_Secure,NULL,NULL);
其中第一个是整数,第二个是指向当前类的指针。
而且,这是我的线程,我认为这就是问题所在
HRESULT WINAPI SecureThread(LPVOID Param)
{
int UID = -1, UserNumber, i;
Secure* m_Secure = (Secure*)Param;
UID = m_Secure->UID;
CGGCBotDlg *h_MainClass = (CGGCBotDlg*)m_Secure->MainClass;
if (UID == -1) return 0;
Sleep(25000);
for (i = 0; i < TOTAL_CLIENTS; i++)
{
if (h_MainClass->Room->g_User[i].UID == UID)
{
UserNumber = i;
break;
}
}
if( h_MainClass->Room->g_User[UserNumber].IsFree == false && h_MainClass->Room->g_User[UserNumber].Secured == false)
h_MainClass->Room->Kick(h_MainClass->Room->g_User[UserNumber].UID,"Didn't Authorized");
return 0;
}
每当创建此线程时,程序就会崩溃,这是一个例外:
First-chance exception at 0x00EC3548 in GGCRoomServer.exe: 0xC0000005: Access violation reading location 0x5D00009C.
Unhandled exception at 0x00EC3548 in GGCRoomServer.exe: 0xC0000005: Access violation reading location 0x5D00009C.