UNIT Createvirus(LPVOID pParam);
int m_mutex=0;
HANDLE hMutex;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
hMutex=CreateMutex(NULL,FALSE,NULL);
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("致命错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
AfxBeginThread(Createvirus);
WaitForSingleObject(hMutex,INFINITE);
m_mutex=1;
ReleaseMutex(hMutex);
} return nRetCode;
}
UNIT Createvirus(LPVOID pParam)
{
WaitForSingleObject(hMutex,INFINITE);
m_mutex=0;
AfxMessageBox("你好");
ReleaseMutex(hMutex);
}
建工程也加了MFC支持了,但 语法错误 : 缺少“;”(在标识符“Createvirus”的前面)
e:\VCprogram\Uconsole\Uconsole.cpp(19) : error C2501: “UNIT” : 缺少存储类或类型说明符
e:\VCprogram\Uconsole\Uconsole.cpp(37) : error C2665: “AfxBeginThread” : 2 个重载中没有一个可以转换参数 1(从“int (__cdecl *)(LPVOID)”类型)
e:\Tools\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxwin.h(4108): 可能是“CWinThread *AfxBeginThread(CRuntimeClass *,int,UINT,DWORD,LPSECURITY_ATTRIBUTES)”
试图匹配参数列表“(int (__cdecl *)(LPVOID))”时
e:\VCprogram\Uconsole\Uconsole.cpp(47) : error C2146: 语法错误 : 缺少“;”(在标识符“Createvirus”的前面)
e:\VCprogram\Uconsole\Uconsole.cpp(47) : error C2501: “UNIT” : 缺少存储类或类型说明符
e:\VCprogram\Uconsole\Uconsole.cpp(47) : error C2086: “int UNIT” : 重定义
e:\VCprogram\Uconsole\Uconsole.cpp(19) : 参见“UNIT”的声明
e:\VCprogram\Uconsole\Uconsole.cpp(53) : warning C4508: “Createvirus” : 函数应返回一个值;假定“void”返回类型
1.很多未声明的错,我不都声明成全局了吗?
2.线程如果不加Sleep是不是可以一直执行完毕再让主线程运行?
int m_mutex=0;
HANDLE hMutex;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
hMutex=CreateMutex(NULL,FALSE,NULL);
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("致命错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
AfxBeginThread(Createvirus);
WaitForSingleObject(hMutex,INFINITE);
m_mutex=1;
ReleaseMutex(hMutex);
} return nRetCode;
}
UNIT Createvirus(LPVOID pParam)
{
WaitForSingleObject(hMutex,INFINITE);
m_mutex=0;
AfxMessageBox("你好");
ReleaseMutex(hMutex);
}
建工程也加了MFC支持了,但 语法错误 : 缺少“;”(在标识符“Createvirus”的前面)
e:\VCprogram\Uconsole\Uconsole.cpp(19) : error C2501: “UNIT” : 缺少存储类或类型说明符
e:\VCprogram\Uconsole\Uconsole.cpp(37) : error C2665: “AfxBeginThread” : 2 个重载中没有一个可以转换参数 1(从“int (__cdecl *)(LPVOID)”类型)
e:\Tools\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxwin.h(4108): 可能是“CWinThread *AfxBeginThread(CRuntimeClass *,int,UINT,DWORD,LPSECURITY_ATTRIBUTES)”
试图匹配参数列表“(int (__cdecl *)(LPVOID))”时
e:\VCprogram\Uconsole\Uconsole.cpp(47) : error C2146: 语法错误 : 缺少“;”(在标识符“Createvirus”的前面)
e:\VCprogram\Uconsole\Uconsole.cpp(47) : error C2501: “UNIT” : 缺少存储类或类型说明符
e:\VCprogram\Uconsole\Uconsole.cpp(47) : error C2086: “int UNIT” : 重定义
e:\VCprogram\Uconsole\Uconsole.cpp(19) : 参见“UNIT”的声明
e:\VCprogram\Uconsole\Uconsole.cpp(53) : warning C4508: “Createvirus” : 函数应返回一个值;假定“void”返回类型
1.很多未声明的错,我不都声明成全局了吗?
2.线程如果不加Sleep是不是可以一直执行完毕再让主线程运行?
2、线程需要__stdcall
HANDLE hMutex;DWORD WINAPI Createvirus(LPVOID pParam)
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
hMutex=CreateMutex(NULL,FALSE,NULL);
{
// TODO: 在此处为应用程序的行为编写代码。
HANDLE hdl = CreateThread(NULL,0,Createvirus,NULL,0,NULL);
CloseHandle(hdl);
WaitForSingleObject(hMutex,INFINITE);
m_mutex=1;
ReleaseMutex(hMutex);
} return nRetCode;
}DWORD WINAPI Createvirus(LPVOID pParam)
{
WaitForSingleObject(hMutex,INFINITE);
m_mutex=0;
MessageBox(NULL,"你好","你好",0);
ReleaseMutex(hMutex);
return 0;
}