windows线性编程
#include <iostream>#include <windows.h>
using namespace std;
/*
HANDLE WINAPI CreateThread
{
LPSECURITY_ATTRIBUTES ipThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_STRAT_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreateFlags,
LPDWORD lpThreadId
}
*/
DWORD WINAPI MyThreadStart(LPVOID);
int main()
{
HANDLE hThread;
DWORD dwThreadId;
hThread = CreateThread(
NULL,
0,
&MyThreadStart,
"Hello, World",
0,
&dwThreadId);
if (!hThread)
{
cout << "Thread Create error:" << GetLastError() << endl;
system("pause");
}
cout << GetCurrentThreadId() << ": Create thread " << hThread
<< dwThreadId << endl;
//等待线程退出
WaitForSingleObject(hThread, INFINITE);
DWORD dwExitCode;
GetExitCodeThread(hThread, &dwExitCode);
cout << GetCurrentThreadId() << ":Thread exited: " << dwExitCode;
CloseHandle(hThread);
system("pause");
return 0;
}
DWORD WINAPI MyThreadStart(LPVOID lpParameter)
{
cout << GetCurrentThreadId() << ": "
<< reinterpret_cast< char* >(lpParameter);
return 0;
}
30 E:\线性编程\CreateThread.cpp invalid conversion from `const void*' to `void*'
30 E:\线性编程\CreateThread.cpp initializing argument 4 of `void* CreateThread(_SECURITY_ATTRIBUTES*, DWORD, DWORD (*)(void*), void*, DWORD, DWORD*)'