VC中的win32控制台程序,然后包含MFC的程序,用CreateThread()向其对应函数传参数的问题
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "test.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// The one and only application object
CWinApp theApp;
using namespace std;
static int count=5;
static HANDLE h1=NULL;
static HANDLE h2;
DWORD dwfun;
int func1(int *a);
void func2();
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
h1=CreateThread((LPSECURITY_ATTRIBUTES)NULL, // 默认的安全属性指针
0, // 线程堆栈大小
(LPTHREAD_START_ROUTINE)func1, // 线程所要执行的函数
(LPVOID) &count, // 线程对应函数要传递的参数
0, // 线程创建后所处的状态,为0表示立即执行,若为CREATE_SUSPENDED则为创建后挂起,需用ResumeThread()激活后才可执行
&dwfun); // 线程标识符指针
Sleep(5000);
CloseHandle(func1);
ExitThread(0);
return nRetCode;
}
//注意函数里的参数一定要使用指针类型,因为LPVOID是指针类型,在函数中使用的时候用指针的引用
int func1(int *a)
{
printf("This is a running thread!\n%d\n",2**a);
return 0;
}
转载于:https://blog.51cto.com/javavwv/1632077