Click here to Skip to main content
15,914,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Typedef and more Pin
Christian Graus8-Apr-02 23:19
protectorChristian Graus8-Apr-02 23:19 
GeneralRe: Typedef and more Pin
Rickard Andersson208-Apr-02 23:22
Rickard Andersson208-Apr-02 23:22 
GeneralRe: Typedef and more Pin
Christian Graus8-Apr-02 23:25
protectorChristian Graus8-Apr-02 23:25 
GeneralRe: Typedef and more Pin
Rickard Andersson208-Apr-02 23:28
Rickard Andersson208-Apr-02 23:28 
GeneralRe: Typedef and more Pin
Roger Allen9-Apr-02 1:12
Roger Allen9-Apr-02 1:12 
GeneralRe: Typedef and more Pin
Rickard Andersson208-Apr-02 23:20
Rickard Andersson208-Apr-02 23:20 
GeneralRe: Typedef and more Pin
Lakitu8-Apr-02 23:24
Lakitu8-Apr-02 23:24 
GeneralRe: Typedef and more Pin
NicholasCougar9-Apr-02 16:19
NicholasCougar9-Apr-02 16:19 
The codes are from Multithreading Applications in Win32 written by Jim Beveridge & Robert Wiener

First, please study the second and sixth parameters.

unsigned long _beginthreadex(
void *security,
unsigned stack_size,
unsigned (* start_address)(void *),
void *arglist,
unsigned initflag,
unsigned *thrdaddr);

HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWROD lpThreadId);


According to Jim Beveridge & Robert Wiener' point of view, the function _beginthreadex() is the coat of CreateThread() and the types of its parameters have been changed for the sake of being adoptable to other operation system. While, as the CloseHandle() must be called at last, programmers can't get rid of "window.h". Another side effect is, though C compiler makes no difference between DWORD and unsigned (in fact unsigned int), C++ compiler doen't think so.

As CreateThread() is inside _beginthreadex(), its parameters are less likely to be modified. Defining parameters according to CreateThread() is smarter. Since the parameters must be accepted by _beginthreadex(), the codes we discussing must appear there. The true meaning of the codes is: force type convertion before calling _beginthreadex().

the following are codes in all:<may jim="" and="" robert="" can="" forgive="" me,just="" for="" discussion="">

//The beginning of codes


#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <process.h>

typedef unsigned (WINAPI *PBEGINTHREADEX_THREADFUNC)(
LPVOID lpThreadParameter
);
typedef unsigned *PBEGINTHREADEX_THREADID;

int main()
{
HANDLE hThread;
DWORD dwThreadId;
int i=0;
hThread = (HANDLE) _beginthreadex(NULL,
0,
(PBEGINTHREADEX_THREADFUNC)ThreadFunc, // Attention, Plz
(LPVOID) i,
0,
(PBEGINTHREADEX_THREADID) & dwThreadId // Attention, Plz
);
if(hThread)
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
return EXIT_SUCCESS;
}


DWORD WINAPI ThreadFunc(LPVOID n)
{
// Do something...
return 0;
}

//The end of codes

My opinion is, to be a best programmer, one should no only learn how to coding, but methodology inside as well. It's not for kids, its for a true programmer.



Best regard.

I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
GeneralCRYSTL32.OCX problem ! Pin
Hadi Rezaee8-Apr-02 23:04
Hadi Rezaee8-Apr-02 23:04 
GeneralRe: CRYSTL32.OCX problem ! Pin
l a u r e n9-Apr-02 0:56
l a u r e n9-Apr-02 0:56 
GeneralRe: CRYSTL32.OCX problem ! Pin
Hadi Rezaee9-Apr-02 4:00
Hadi Rezaee9-Apr-02 4:00 
GeneralRe: CRYSTL32.OCX problem ! Pin
Hadi Rezaee9-Apr-02 10:02
Hadi Rezaee9-Apr-02 10:02 
GeneralWord Automation - Extra Info on Tables.. Pin
Braulio Dez8-Apr-02 22:41
Braulio Dez8-Apr-02 22:41 
GeneralSTL and heap management Pin
Haakon S.8-Apr-02 22:26
Haakon S.8-Apr-02 22:26 
GeneralRe: STL and heap management Pin
Christian Graus8-Apr-02 23:21
protectorChristian Graus8-Apr-02 23:21 
GeneralRe: STL and heap management Pin
Haakon S.9-Apr-02 0:20
Haakon S.9-Apr-02 0:20 
GeneralRe: STL and heap management Pin
Joao Vaz9-Apr-02 1:07
Joao Vaz9-Apr-02 1:07 
GeneralRe: STL and heap management Pin
Haakon S.9-Apr-02 1:50
Haakon S.9-Apr-02 1:50 
GeneralRe: STL and heap management Pin
Joao Vaz9-Apr-02 3:48
Joao Vaz9-Apr-02 3:48 
GeneralRe: STL and heap management Pin
Tim Smith9-Apr-02 4:10
Tim Smith9-Apr-02 4:10 
GeneralRe: STL and heap management Pin
Joao Vaz9-Apr-02 4:49
Joao Vaz9-Apr-02 4:49 
GeneralRe: STL and heap management Pin
Haakon S.9-Apr-02 8:17
Haakon S.9-Apr-02 8:17 
GeneralRe: STL and heap management Pin
Joao Vaz9-Apr-02 9:56
Joao Vaz9-Apr-02 9:56 
GeneralRe: STL and heap management Pin
Tim Smith9-Apr-02 8:44
Tim Smith9-Apr-02 8:44 
GeneralRe: STL and heap management Pin
Joao Vaz9-Apr-02 10:03
Joao Vaz9-Apr-02 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.