最近研究线程好蛋疼,创建了这样的一个类,参考了MSDN还是出错,求救啊
- C/C++ code
#include <Windows.h>using namespace System::Windows::Forms; class yThread { public: void start(); protected: DWORD WINAPI ThreadProc(LPVOID lpParameter); }; void yThread::start() { HANDLE hwn1; hwn1 =CreateThread(NULL,0,ThreadProc,0,0,NULL); } DWORD WINAPI yThread::ThreadProc(LPVOID lpParameter ) { MessageBox::Show("!"); return 0 ; }
编译错误
1>------ Build started: Project: tests, Configuration: Debug Win32 ------
1>Build started 2012/7/22 21:47:07.
1>InitializeBuildStatus:
1> Touching "Debug\tests.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1> All outputs are up-to-date.
1> tests.cpp
1>c:\files\编程\visual studio projects\tests\tests\myThread.h(16): error C3867: 'yThread::ThreadProc': function call missing argument list; use '&yThread::ThreadProc' to create a pointer to member
1>c:\files\编程\visual studio projects\tests\tests\myThread.h(9): error C3641: 'yThread::ThreadProc' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.43
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
------解决方案--------------------------------------------------------
线程函数定义为static
------解决方案--------------------------------------------------------
还有,你不能用/clr:pure 或者 /clr:safe 方式,使用非托管api
既然用托管,为何不用
System::Threading