Click here to Skip to main content
15,917,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Any Ideas? Pin
Joan M16-Apr-03 21:50
professionalJoan M16-Apr-03 21:50 
AnswerRe: Any Ideas? Pin
Michael P Butler16-Apr-03 23:32
Michael P Butler16-Apr-03 23:32 
GeneralModifiying context menu of highlighted text Pin
nlyang16-Apr-03 20:35
nlyang16-Apr-03 20:35 
GeneralCrypto++ question Pin
DREVET Olivier16-Apr-03 19:44
DREVET Olivier16-Apr-03 19:44 
GeneralRe: Crypto++ question Pin
Zdeslav Vojkovic17-Apr-03 0:13
Zdeslav Vojkovic17-Apr-03 0:13 
GeneralRe: Crypto++ question Pin
DREVET Olivier17-Apr-03 1:20
DREVET Olivier17-Apr-03 1:20 
GeneralRe: Crypto++ question Pin
DREVET Olivier17-Apr-03 19:22
DREVET Olivier17-Apr-03 19:22 
GeneralMultithreading Problem Pin
16-Apr-03 18:09
suss16-Apr-03 18:09 
I'm trying to do multithreading in a Win32 C++ ( DirectX ) game. I've been having this compile error:

*******
error C2440: 'type cast' cannot convert from 'overloaded-function' to 'LPTHREAD_START_ROUTINE'
********

Now here's the question. I have two versions, a long version and short version, in case anyone can answer the short version so that you dont need to read the long version.

*** Short question:
Can you pass a class function through the 3rd argument of CreateThread?

*** Long question:

Here's a small example code of what I'm trying to do:

////////////////////////////////////////////////////
// MAIN.H
////////////////////////////////////////////////////
#pragma once

class CMyClass
{
private:
HANDLE m_hThread;
DWORD m_ThreadID;

public:
void FunctionToCallThread( void );
DWORD WINAPI Thread( DWORD );
};


//////////////////////////////////////////////////////
// MAIN.CPP
//////////////////////////////////////////////////////
#include <stdio.h>
#include <windows.h>

#include "Main.h"

void main( void )
{
CMyClass MyClass;

MyClass.FunctionToCallThread( );
}

void CMyClass::FunctionToCallThread( void )
{
m_hThread = CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE )Thread, 0, 0, &m_ThreadID );

printf( "Starting\n" );
Sleep( 1000 );

for( int i = 0; i < 50; i++ )
{
printf("u\n");
Sleep( 1000 );
}
}

DWORD WINAPI CMyClass::Thread( DWORD data )
{
for( int i = 0; i < 50; i++ )
{
printf("hi\n");
Sleep( 1000 );
}

CloseHandle( hThread );

return data;
}

//////////////////////////////////////////////////
// end code
//////////////////////////////////////////////////

So here's what's the program does:
1) Create a class from CMyClass called MyClass
2) Call MyClass.FunctionToCallThread( )
3) MyClass.FunctionToCallThread starts a thread from the function MyClass.Thread( DWORD ) (or it should anyway). Then prints 'u\n' every second 50 times
4) The thread should then print 'hi\n' every second 50 times then closes itself.

.................................................
I've been looking on the net for the past 3 hours why this wouldn't work. on MSDN, Google, and even articles on here. I'd appreicate if any of you could help me with this Smile | :) And thanks in advance.

Doug
GeneralRe: Multithreading Problem Pin
Joe Woodbury16-Apr-03 19:00
professionalJoe Woodbury16-Apr-03 19:00 
Questionhow to get handle Pin
Prog Mmer16-Apr-03 17:23
Prog Mmer16-Apr-03 17:23 
GeneralBasic iphlpapi questions Pin
autekre16-Apr-03 16:57
autekre16-Apr-03 16:57 
QuestionThere is problem,I write a small demo project for demonstrate this problem,who has clue to solve the problem? Pin
Jeef16-Apr-03 16:36
Jeef16-Apr-03 16:36 
GeneralQuestions on behavior of code Pin
yukikyo16-Apr-03 16:16
yukikyo16-Apr-03 16:16 
Generalanyone know of a free utility that can... Pin
Roman Nurik16-Apr-03 15:09
Roman Nurik16-Apr-03 15:09 
GeneralRe: anyone know of a free utility that can... Pin
Nish Nishant16-Apr-03 19:06
sitebuilderNish Nishant16-Apr-03 19:06 
GeneralRe: anyone know of a free utility that can... Pin
Joan M16-Apr-03 21:52
professionalJoan M16-Apr-03 21:52 
GeneralMFC & MDI Pin
Brian Shifrin16-Apr-03 14:54
Brian Shifrin16-Apr-03 14:54 
GeneralRe: MFC & MDI Pin
Brian Shifrin16-Apr-03 14:56
Brian Shifrin16-Apr-03 14:56 
Generalglobal variables Pin
Gabor Kalman16-Apr-03 13:34
Gabor Kalman16-Apr-03 13:34 
GeneralRe: global variables Pin
Maximilien16-Apr-03 13:50
Maximilien16-Apr-03 13:50 
GeneralRe: global variables Pin
Taka Muraoka16-Apr-03 13:56
Taka Muraoka16-Apr-03 13:56 
GeneralRe: global variables Pin
Christian Graus16-Apr-03 14:14
protectorChristian Graus16-Apr-03 14:14 
Generalstatic libraries Pin
jason9916-Apr-03 12:46
jason9916-Apr-03 12:46 
GeneralSetPaneText not working Pin
jcjollant16-Apr-03 12:16
jcjollant16-Apr-03 12:16 
GeneralUsing Custom Classes in AFX message maps Pin
Anonymous16-Apr-03 10:07
Anonymous16-Apr-03 10:07 

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.