Click here to Skip to main content
14,428,673 members
Rate this:
Please Sign up or sign in to vote.
See more:
Following is the Cthread.h file:

#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;

	/***local Thread***/
	//automatically set the default values of running, end, tid and handle variables

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



The following is the Cthread.cpp file:

#include "Cthread.h"


	//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);


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!
Rate this:
Please Sign up or sign in to vote.

Solution 1

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).
CPallini 9-Apr-15 3:46am
Rate this:
Please Sign up or sign in to vote.

Solution 2

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).
Rate this:
Please Sign up or sign in to vote.

Solution 3

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.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100