Click here to Skip to main content
15,885,920 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following is the Cthread.h file:

C++
#ifndef Cthread_H_
#define Cthread_H_

#include <windows.h>
#include <process.h>
#include <time.h>
#include <algorithm>

class Cthread
{
	
	//This is the handle to our thread system give us when
	//Thread is created.
	HANDLE MySendThread;
	DWORD MySendThreadId;

	HANDLE MyReceiveThread;


public:
	/***local Thread***/
	//automatically set the default values of running, end, tid and handle variables
	Cthread();

        /*Receive Thread:*/
	void ReceiveThread(void* data);
	
	/*Send Thread:*/
	DWORD WINAPI SendThread(LPVOID lpParam); 

};

#endif
/*Cthread_H*/



The following is the Cthread.cpp file:

C++
#include "Cthread.h"

/******************Threads***************************/

Cthread::Cthread()
{
	//This means thread is not running
	Running = false;
	//Our signal for stopping thread, in this case not.
	End = false;

	//Set default values for identifier and handle
	MySendThread = 0;
	MyReceiveThread = 0;
}

/*Receive Thread initiator*/
void Cthread::ReceiveThread(void* data)
{

	//VNSelement = VNS(EDIP_UDP_PORT_NO);
}

/*Send Thread initiator*/
DWORD WINAPI Cthread::SendThread(LPVOID lpParam)
{
	int result;
    //char * mytxdata = "Hello";
    int dataSize;
    char * mytxdata;
   
	char sendArray[1500] = { 0x01, 0x02, 0x03 }; 

    //mytxdata = reinterpret_cast<char*>(&test);
    //dataSize = sizeof(test);

    while (1)
    {

        //result = UdpServer::send ( socketno, mytxdata, dataSize, VNS_UDP_IP_NO, EDIP_UDP_PORT_NO );

        if ( result == 0 )
        {
            //cout << "Send!\n";
        }
        
    }
}


/*Starts Thread*/
void Cthread::start()
{
	//Pass static_run function and whole object as parameter.
	//Get handle to our thread and identifier (tid)
	MySendThread = CreateThread(NULL,0, SendThread, 0, 0, &MySendThreadId );
	MyReceiveThread = (HANDLE)_beginthread( &ReceiveThread, 0, 0);

	//VNSelement.VNS_Initiate_Decode();
}


The problem is this: when I run the code program above, it gives me the following errors:


IntelliSense: argument of type "void (Cthread::*)(void *data)" is incompatible with parameter of type "void (__cdecl *)(void *)"

IntelliSense: argument of type "DWORD (__stdcall Cthread::*)(LPVOID lpParam)" is incompatible with parameter of type "LPTHREAD_START_ROUTINE"

error C3867: 'Cthread::SendThread': function call missing argument list; use '&Cthread::SendThread' to create a pointer to member

error C2276: '&' : illegal operation on bound member function expression


I'm kind of confused for the moment, any help is appreciated. thanks!
Posted

The thread functions passed via the start_address parameters must be static. So define them as static in the header file:
/*Receive Thread:*/
static void ReceiveThread(void* data);
	
/*Send Thread:*/
static DWORD WINAPI SendThread(LPVOID lpParam);


The error message for C3867 tells you what to do.

The error C2276 is solved by passing the function in the same style as indicated by the C3867 message (&Cthread::ReceiveThread).
 
Share this answer
 
Comments
CPallini 9-Apr-15 3:46am    
5.
As Jochen Arndt already stated, your thread function cannot be an instance method of your class. If you need access to a class instance, use the technique shown at the bottom of this page: "Callbacks, Threads, and MFC"[^] (the example refers to MFC, but the technique is more general).
 
Share this answer
 
for that use the functions signatures must match exactly. Now your funcs are member funcs in the class. They must be static in the class or global funcs. You can use global objects in such functions or the input parameter is poiting to the main object or data. Here you will find som example code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900