能力值:
(RANK:650 )
|
-
-
2 楼
//thread.h
#pragma once
class CThreadTest
{
public:
CThreadTest(void);
~CThreadTest(void);
public:
unsigned long aaa();
private:
static unsigned long __stdcall bbb(void *pParam);
public:
unsigned long m_dwData;
unsigned long m_dwTid;
void* m_hThread;
};
//thread.cpp
#include "thread.h"
#include <windows.h>
CThreadTest::CThreadTest(void)
{
}
CThreadTest::~CThreadTest(void)
{
}
unsigned long __stdcall CThreadTest::bbb(LPVOID pParam)
{
CThreadTest* ccc = (CThreadTest*)pParam;
ccc->m_dwData = 12345678;
return 0;
}
unsigned long CThreadTest::aaa()
{
m_hThread = CreateThread(NULL, 0, bbb, this, 0, &m_dwTid);
WaitForSingleObject(m_hThread, INFINITE);
return m_dwData;
}
//test.cpp
#include <windows.h>
#include "thread.h"
void main()
{
CThreadTest* test = new CThreadTest;
DWORD a = test->aaa();
}
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
谢谢。
自己卡在这句声明上
static unsigned long __stdcall bbb(void *pParam);
static和__stdcall缺一不可
有空的话,不吝赐教下缘由
再次感谢
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
学习中................................
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
问题出在bbb的类型上把
bbb是一个类成员函数名,有CThreadTest::修饰的函数指针
及应该是下面这样的一个指针
unsigned long __stdcall CThreadTest::(*)(void *)
而CreateThread(...)函数需要的是unsigned long __stdcall (*)(void *)指针所以类型不匹配吧
|
|
|