Hi All, I need to implment a callback to a Nonstatic member function of a class. Which will be invoked through a DLL.DLL is an independent library.No dependency with the class. I Implemented with a static function. I need to know how it will be for a non static member function. My code is as follows for static implementation. I need to change it for a non static .Please help. class CCallbackTester { public: static int __stdcall CompareInts(const byte* velem1, const byte* velem2); }; int __stdcall CCallbackTester::CompareInts(const byte* velem1, const byte* velem2) { int elem1 = *(int*)velem1; int elem2 = *(int*)velem2; if(elem1 < elem2) return -1; if(elem1 > elem2) return 1; return 0; } int main(int argc, char* argv[]) { int i; int array[] = {22, 1, 3210, 2109, 1098}; Bubblesort((byte*)array, 5, sizeof(array[0]), &CCallbackTester::CompareInts); cout << "After the sorting\n"; for(i=0; i<5; i++) cout << array[i] << '\n'; getch(); } in DLL Bubblesort is as follows. void DLLDIR CALLBACK Bubblesort(byte* array, int size, int elem_size, CompareFunction cmpFunc) { for(int i=0; i<size; i++) { for(int j=0; j<size-1; j++) { if(1 == (*cmpFunc)(array+j*elem_size, array+(j+1)*elem_size)) { byte* temp = new byte[elem_size]; memcpy(temp, array+j*elem_size, elem_size); memcpy(array+j*elem_size, array+(j+1)*elem_size, elem_size); memcpy(array+(j+1)*elem_size, temp, elem_size); delete [] temp; } } } } Thanks San
San 0
Posts
-
Callback to a Non static Member function in C++ need to be called from a DLL -
ToolTip with Close buttonI there any sample code available?
-
ToolTip with Close buttonHi all, How to add a close button to System.Windows.Forms.ToolTip ? Please help me. Thanks in advance San
-
Exception handling in C++Hi all, What is wrong in this problem. Is this the right way to handle? #include class MyErrorClass { char *reason; int *i; public: MyErrorClass(char *r) { i = new int[6]; cout<<;"Constructor<<endl; reason = r; cout<<reason<<<endl; } char* giveReason() { return reason; } ~MyErrorClass() { cout<<"destructor"<<endl; delete[] i; } }; void main() { try { throw MyErrorClass("error"); } catch (MyErrorClass &e) { cout<<"Exception caught --- <<e.giveReason()<<endl; } } Thanks San
-
Private DestructorCould please send me some sample code
-
Private DestructorHi all, What is the use of declaring a private destructor? Where we are using this? Can anybody tell an example Thanks San
-
DeletegateHi All, I have developed a formbased application. In which I need to use another dll which contains some callback. For using the callback inside the DLL from C# application what should be done?? In dll there is a struct which stores the callback pointers and one function uses to register this callback. Please help Regards San
-
Size of a ClassYes I got an exception since Abc is a class. So how is to calculate the size?
-
Size of a ClassWhen I given as per your suggestion I got an exception as follows. An unhandled exception of type 'System.ArgumentException' occurred in exe Additional information: Type 'class' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
-
Size of a ClassHi all, I have a class public class Abc { private UInt32 x; private UInt32 y; private Int32 z; }; I need to get the size of the class. Please help! Thanks in Advance. San
-
Structure converstion to Bytearraythankyou so much
-
DDE communicationSorry..Some problem while sending the Question
-
Structure converstion to BytearrayCould u please send any sample code or link to imlement this. I am a beginner to this Regards, San
-
DDE communicationHi all, How to write a dda communication program? Regards, Sangetha
-
DDEHi all, How to write a dda communication program? Regards, Sangetha
-
Structure converstion to BytearrayC# program is wrting the data. C program is reading the data. Regards, Sangeetha
-
Structure converstion to BytearrayHi All, I have a struct in C# application used for serial port communication. I have to read the struct value send from C# application to a C application. What is to be done??? Thanks in Advance San
-
Setting the Maxlength of the TreeNode textHi all, I want to restrict the Tree Node label length,when the label is being edited. How can i accomplish this. Thanks in Advance, San
-
Bitmap on a ButtonHow is it possible to put a bimap on a button?? Pls help San
-
Close PortHi.... I am doing a Project in which I want to close a selected port which is opened by another application. How can I Solve the Same? Which function to be used??Please Help Thanks in Advance. SAN