Thanks for the advice but that does not work either.
I tryed both methods you suggested and I get the same error again.
If i try to call CWinApp:SetRegistryKey("SomeCompany")
C2352: 'CWinApp::WriteProfileStringA' : illegal call of non-static member function
I think this problem is something to do with the base class CWinApp.
What I am trying to achive is when a user cancels the dialog box it writes some info to the registry.. It seemed to me that SetRegistryKey was only available in classes derived from CWinApp and that only one class can be dirived from CWinApp.
Because CUserinfo3App is dirived fro CWinApp this seems like the logical place to insert this function.. Thats were I am now..
I could just use the winapi reg funtions to do this but I am trying to get to grips with MFC.
If I have got the wrong end of the stick please let me know..
Can you post the code showing the syntax you're using to call CUserinfo3App::WriteCancelled()?
CUserinfo3App::WriteCancelled(); // Caller
char CancelText = "You will be prompted to enter your account details again the next time you logon";
char CancelTitle = "FYI";
MessageBox( CancelText, CancelTitle, MB_OK | MB_ICONINFORMATION);
You need to refer back to nvoigt's response, you can't call non-static functions like that, and you can't make it static because it calls non-static functions.
You need to call it through your CUserinfo3App instance. Normally MFC automatically creates a global instance of your CWinApp derived class called theApp. So you'd call the functions like
No joy with that, same error.. I'll tidy & zip up the project and will post here
Thanks for your time on this.
Here it is. It contains the relevant code to show the problem.
Maybe my first reply was to generic.
You cannot call non-static methods from a static method.
Given that, if you want to call the two functions from WriteCancelled, this function must not be static.
static void WriteCancelled();
should be replaced by
Now, you have a second problem. A non-static function must be called on an object. You already have an object of your application. You need to make this known to your dialog. Insert the following line on top of your dialog .cpp file:
extern CUserinfo3App theApp;
Now, in the Dialog class, you have access to an instance of CUserInfo3App, called theApp. So now you can call your method on an actual object. Replace your calls to
This compiles fine. ;)
I put the extern line in the dialog*.h file and its working.
I understood what you said about removing static before, but thought it best that I submit the project in its original form.
It was the second problem that was throwing me off. I would never have figured that one out.
Ta very much..