Function name in calling CreateThread() - Programmer

This is a discussion on Function name in calling CreateThread() - Programmer ; Hello, I am trying to write a user interface that fire a thread to do some background job. The working thread is a dialog box method. The definition of the working method is: void CScanSaveDlg::Scan() { // do some time ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Function name in calling CreateThread()

  1. Function name in calling CreateThread()

    Hello,

    I am trying to write a user interface that fire a thread to do
    some background job. The working thread is a dialog box method. The
    definition of the working method is:



    void CScanSaveDlg::Scan()

    {

    // do some time consuming process:

    }



    and I created the thread by using the following createThread()



    void CScanSaveDlg::StartScan()

    {

    HANDLE ScanThread;

    DWORD ThreadID;

    ScanThread=CreateThread(0,0,(LPTHREAD_START_ROUTIN E)(this->Scan()),0,0,&Thre
    adID);

    }





    But I can't compile it and compiler complains with the following error
    message:



    'type cast' : cannot convert from 'void' to 'unsigned long (__stdcall
    *)(void *)'

    Expressions of type void cannot be converted to other types





    What should I do to solve this problem?



    Regards









  2. Re: Function name in calling CreateThread()

    Hello

    > void CScanSaveDlg::Scan()


    As the compiler indicated, the function you're providing to CreateThread()
    is not correct (prototype wise).
    Besides, you need to create it as a static member function or a non-member
    function.

    Refer to MSDN for example about how to use CreateThread()

    HTH
    Elias
    "m a" wrote in message
    news:c4jglj$96f$1@scotsman.ed.ac.uk...
    > Hello,
    >
    > I am trying to write a user interface that fire a thread to do
    > some background job. The working thread is a dialog box method. The
    > definition of the working method is:
    >
    >
    >
    > void CScanSaveDlg::Scan()
    >
    > {
    >
    > // do some time consuming process:
    >
    > }
    >
    >
    >
    > and I created the thread by using the following createThread()
    >
    >
    >
    > void CScanSaveDlg::StartScan()
    >
    > {
    >
    > HANDLE ScanThread;
    >
    > DWORD ThreadID;
    >
    >

    ScanThread=CreateThread(0,0,(LPTHREAD_START_ROUTIN E)(this->Scan()),0,0,&Thre
    > adID);
    >
    > }
    >
    >
    >
    >
    >
    > But I can't compile it and compiler complains with the following error
    > message:
    >
    >
    >
    > 'type cast' : cannot convert from 'void' to 'unsigned long (__stdcall
    > *)(void *)'
    >
    > Expressions of type void cannot be converted to other types
    >
    >
    >
    >
    >
    > What should I do to solve this problem?
    >
    >
    >
    > Regards




  3. Re: Function name in calling CreateThread()

    make scan() static

    static long CScanSaveDlg::Scan()
    {

    }


    "m a" wrote in message
    news:c4jglj$96f$1@scotsman.ed.ac.uk...
    > Hello,
    >
    > I am trying to write a user interface that fire a thread to do
    > some background job. The working thread is a dialog box method. The
    > definition of the working method is:
    >
    >
    >
    > void CScanSaveDlg::Scan()
    >
    > {
    >
    > // do some time consuming process:
    >
    > }
    >
    >
    >
    > and I created the thread by using the following createThread()
    >
    >
    >
    > void CScanSaveDlg::StartScan()
    >
    > {
    >
    > HANDLE ScanThread;
    >
    > DWORD ThreadID;
    >
    >

    ScanThread=CreateThread(0,0,(LPTHREAD_START_ROUTIN E)(this->Scan()),0,0,&Thre
    > adID);
    >
    > }
    >
    >
    >
    >
    >
    > But I can't compile it and compiler complains with the following error
    > message:
    >
    >
    >
    > 'type cast' : cannot convert from 'void' to 'unsigned long (__stdcall
    > *)(void *)'
    >
    > Expressions of type void cannot be converted to other types
    >
    >
    >
    >
    >
    > What should I do to solve this problem?
    >
    >
    >
    > Regards
    >
    >
    >
    >
    >
    >
    >
    >




+ Reply to Thread