Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
header file
class MainClass
{

public:
    MainClass(void);
    ~MainClass(void);
public:
    void RegCallBack();
    static void __stdcall CB_CardEncode2(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData,void *pContext);
};


Cpp file
extern "C"
{

void MainClass:: CB_CardEncode2(unsigned int nCh,ISIL_ENCODE_DATA *pEncData,void *pContext)
{
    ////////////FILEcreate/////////

    FILE *P=fopen("c:/Record/TP5.txt","w");
    fprintf(P, "i am card encode2!!!");
        fclose(P);
}

void RegCallBack()
{
    ISIL_Card_RegEncode2Callback(CB_CardEncode2,NULL);
}


Hi,
i am creating a dll,my problem is that i am passing as a parameter a static member function CB_CardEncode2 in ISIL_Card_RegEncode2Callback(CB_CardEncode2,NULL);
but CB_CardEncode2 member function is not calling.
i dont have idea how to pass a static member function as a parameter in other function and how to call CB_CardEncode2 static member function.

Thanks....





Hi,
I have to make entry point of the RegcallBack()
like
int __stdcall RegCallBack();



C#
__declspec(dllexport)  int __stdcall RegCallBack()
{
        ISIL_Card_RegEncode2Callback1(MainClass::CB_CardEncode2,NULL);
    //ISIL_Card_RegReadEncodeCallback(CB_CardReadEncode, NULL);
    return TRUE;

}

but when the compile then gives error,
please help me.give me any example.

Thanks


VB
when i am using classscope ISIL_Card_RegEncode2Callback1(MainClass::CB_CardEncode2,NULL);
then give this error
Error   1   error C2664: 'ISIL_Card_RegEncode2Callback1' : cannot convert parameter 1 from 'void (__stdcall *)(unsigned int,ISIL_ENCODE_DATA *,void *)' to 'CALL'   c:\documents and settings\administrator\desktop\test\dll_prj\dll_prj\test111\carddemo\mainclass.cpp 180 1   CardDemo


and when using
ISIL_Card_RegEncode2Callback1((CALL)MainClass::CB_CardEncode2,NULL);
then succesful
CB_CardEncode2 function not read.
where am i going wrong .please help me......


thanks
Posted
Updated 8-Feb-12 0:05am
v5
Comments
Lakamraju Raghuram 8-Feb-12 1:21am    
I do not think this will even compile, as you are not using class scope while calling CB_CardEncode2 method.
!!!!

typedef void (__stdcall *CALLBACK)(int, void*);

void Global(CALLBACK pfn)
{
	pfn(10, 0);
}

class MainClass
{
public:
	void Reg();
	static void __stdcall Callback(int i, void* p);
};

void MainClass::Reg()
{
	Global(Callback);
}

void MainClass::Callback(int i, void* p)
{
	cout << i << " " << p << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
	MainClass m;
	m.Reg();

	return 0;
}
 
Share this answer
 
Comments
Lakamraju Raghuram 8-Feb-12 1:47am    
This solution matches the OP's requirement in a better way.
My 5.
I question is very vague and can't be trouble-shooted with the info provided. In general I am giving a code snippet for calling a class static function as a callback.

C++
#include <iostream>
using namespace std;

class MyClass
{
public:
   static int StaticFun(int i)
   {
      cout<<i<<endl;
      return 0;
   }
};

typedef int (*FN)(int);
void RegCallBack(FN pFn)
{
   pFn(100);
}

void main()
{
  RegCallBack(MyClass::StaticFun);
}


Hope this helps.
 
Share this answer
 
v2

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