当前位置:首页
开发技术指南» 文章正文
    引言:

    摘要: 编写activex dll,在html文件中进行调用时,可不可以用<param name="xxx" value="xxxx">这种形式向activex传递参数?注意,是dll的这一种,那种activex控件(编译后扩展名为ocx)的我知道可以传递。 如果可以的话,在activex中如何读取param的值? 新手上路,敬请各位大师大侠不吝......
    摘要: 本人 开始学习,net 但是苦于 没有好的代码学习 买了几本书 多不怎么满意 只有靠csdn 求救 ......


C语言中如何使用多线程(Dev-C++)

尽管Dev-C++可以编译C++程序,我编写的是完全C的程序。我想使用多线程。由于Dev使用的是MinGW编译器,类同Linux下的GCC。但是书上的Posix程序我照搬过来在Dev里面都不能编译。比如  
   
  #include   "pthread.h"  
   
  int   main()  
  {  
  pthread_t   th;   //   这个就出问题了,居然说找不到不能识别pthread_t  
  return   0;  
  }  
   
  总之我现在想做多线程程序,用C语言,环境是Dev-C++,该用什么方法?

NO.1   作者: jiajun2001

MinGW属于Windows操作系统的GCC版本,这个版本不带有Posix   Thread库,但是可以使用Windows本地的API  
  CreateThread等,相关信息察看MSDN即可。

NO.2   作者: henan_lujun

在C语言中,最好使用_beginthreadex函数来创建线程,该函数的参数和CreateThread的参数相同,但是它比CreateThread做更多的事情,要关闭线程就用对应的函数:_endthreadex

NO.3   作者: jsjjms

在c中使用多线程真是难为了这门语言.呵呵。

NO.4   作者: liuhaimiao

用wingcc

NO.5   作者: sjf331

你用什么操作系统,如果想写通用的,就用ace吧。

NO.6   作者: 51365133

MSDN例子  
  #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   screens   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();  
  }  
 


    摘要: vb下编写activex dll,在html文件中进行调用时,可不可以用<param name="xxx" value="xxxx">这种形式向activex传递参数?注意,是dll的这一种,那种activex控件(编译后扩展名为ocx)的我知道可以传递。 如果可以的话,在activex中如何读取param的值? 新手上路,敬请各位大师大......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE