Callback Function for Windows Form

Ok I have a Windows form which calls a DLL, both of which written by me.

I have a start form which is the main form which calls the DLL (frontend form).
The DLL processes data passed to it from the form and returns results.
I have a second form which is opened after the DLL is called, which shows the results passed back from the DLL (results form).

So I have a public function on the results form (although it doesn't actually do anything):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	public ref class Results : public System::Windows::Forms::Form
	{
	public:
		Results(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
	public:
		void updateStatus(unsigned __int64 number, int field, char* status)
		{
			return;
		}


The function is defined in the dll header:
1
2
3
4
5
#ifdef EXPORTING_DLL
extern __declspec(dllexport) int startRecovery(int argc, char **argv, char* caseRoot, int(*updateStatus)(unsigned __int64 number, int field, char* status);
#else
extern __declspec(dllimport) int startRecovery(int argc, char **argv, char* caseRoot, int(*updateStatus)(unsigned __int64 number, int field, char* status));
#endif 


So in my frontend form I try to call the DLL:
startRecovery(8,arguments, path, *****);

My problem is where I have ****, I'm not sure how i reference the pointer for the updateStatus function.

Do I have to create an instance of the object (Resultsform ^frmRes = gcnew Resultsform)?
Either way I can't seem to figure how to pass the address for the function. Any ideas?

You can create a function pointer, give it the addres of the member of the class Results (for which you first have to make an instance).
1
2
3
Results ResultsInstance; // calls the constructor
typedef int (*func_pointer)(unsigned __int64 number, int field, char* status);
func_pointer = &ResultsInstance.updateStatus;


Then pass func_pointer to the startRecovery and you can use it in the dll.
Topic archived. No new replies allowed.