我在学习sdk多线程编程的过程中,碰到这样一个问题,说资料库\sdk\multithread\multithread.cpp(101) : error C2065: '_endthread' : undeclared identifier
F:\程序资料库\sdk\multithread\multithread.cpp(112) : error C2065: '_beginthread' : undeclared identifier
可我一加了头文件
#include <process.h> /* _beginthread, _endthread 怎么还不行啊
F:\程序资料库\sdk\multithread\multithread.cpp(112) : error C2065: '_beginthread' : undeclared identifier
可我一加了头文件
#include <process.h> /* _beginthread, _endthread 怎么还不行啊
解决方案 »
- CFrameWnd//的OnCreate函数里代码什么意思?
- 请问VC中与数据库SQL2000交互中更新语句怎么写啊,写了好几次都不成功。
- 请教关于字符串查找与替换的问题
- 用VC做聊天室,有个问题请教!(2)
- vs2005打包发布软件需要添加哪些DLL文件!?
- 估计这个问题是超难了,如何在任务栏上显示出图标!
- 在无模式对话框下,切换输入法时会使该对话框得不到焦点,明天要验收,十万火急
- love_vc
- 请问怎么做一个打开文件夹的对话框?
- 奇怪:一个程序(vc++),运行很好,可是当再在程序中多声明一个变量的时候,程序出现了非法操作错误,怎么回事?
- GetWindowText的问题
- 哪儿有想WORD那样的颜色选择对话框
/* BEGTHRD.C illustrates multiple threads using functions:
*
* _beginthread _endthread
*
*
* This program requires the multithreaded library. For example,
* compile with the following command line:
* CL /MT /D "_X86_" BEGTHRD.C
*
* If you are using the Visual C++ development environment, select the
* Multi-Threaded runtime library in the compiler Project Options dialog
* box.
*
*/#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <stddef.h>
#include <stdlib.h>
#include <conio.h>void Bounce( void *ch );
void CheckKey( void *dummy );/* GetRandom returns a random integer between min and max. */
#define GetRandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))BOOL repeat = TRUE; /* Global repeat flag and video variable */
HANDLE hStdOut; /* Handle for console window */
CONSOLE_SCREEN_BUFFER_INFO csbi; /* Console information structure */void main()
{
CHAR ch = 'A'; hStdOut = GetStdHandle( STD_OUTPUT_HANDLE ); /* Get display screen's text row and column information. */
GetConsoleScreenBufferInfo( hStdOut, &csbi ); /* Launch CheckKey thread to check for terminating keystroke. */
_beginthread( CheckKey, 0, NULL ); /* Loop until CheckKey terminates program. */
while( repeat )
{
/* On first loops, launch character threads. */
_beginthread( Bounce, 0, (void *) (ch++) ); /* Wait one second between loops. */
Sleep( 1000L );
}
}/* CheckKey - Thread to wait for a keystroke, then clear repeat flag. */
void CheckKey( void *dummy )
{
_getch();
repeat = 0; /* _endthread implied */}/* Bounce - Thread to create and and control a colored letter that moves
* around on the screen.
*
* Params: ch - the letter to be moved
*/
void Bounce( void *ch )
{
/* Generate letter and color attribute from thread argument. */
char blankcell = 0x20;
char blockcell = (char) ch;
BOOL first = TRUE;
COORD oldcoord, newcoord;
DWORD result;
/* Seed random number generator and get initial location. */
srand( _threadid );
newcoord.X = GetRandom( 0, csbi.dwSize.X - 1 );
newcoord.Y = GetRandom( 0, csbi.dwSize.Y - 1 );
while( repeat )
{
/* Pause between loops. */
Sleep( 100L ); /* Blank out our old position on the screen, and draw new letter. */
if( first )
first = FALSE;
else
WriteConsoleOutputCharacter( hStdOut, &blankcell, 1, oldcoord, &result );
WriteConsoleOutputCharacter( hStdOut, &blockcell, 1, newcoord, &result ); /* Increment the coordinate for next placement of the block. */
oldcoord.X = newcoord.X;
oldcoord.Y = newcoord.Y;
newcoord.X += GetRandom( -1, 1 );
newcoord.Y += GetRandom( -1, 1 ); /* Correct placement (and beep) if about to go off the screen. */
if( newcoord.X < 0 )
newcoord.X = 1;
else if( newcoord.X == csbi.dwSize.X )
newcoord.X = csbi.dwSize.X - 2;
else if( newcoord.Y < 0 )
newcoord.Y = 1;
else if( newcoord.Y == csbi.dwSize.Y )
newcoord.Y = csbi.dwSize.Y - 2; /* If not at a screen border, continue, otherwise beep. */
else
continue;
Beep( ((char) ch - 'A') * 100, 175 );
}
/* _endthread given to terminate */
_endthread();
}
#ifdef MT
_endthread(...........
#endif
具体请这样:project->settings->c/c++->use run time libray->multithreaded
手工编译的时候加上 /DMT选项!给分吧,记住以后再加点!