Thread: Error c2352 in MSVC6

  1. #16
    Unregistered
    Guest
    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")

    I get

    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..

    Thx

    P..

  2. #17
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Can you post the code showing the syntax you're using to call CUserinfo3App::WriteCancelled()?

  3. #18
    Unregistered
    Guest
    void CUserinfo3Dlg::OnCancel()
    {
    CDialog::OnCancel();

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

    }

  4. #19
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    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

    theApp.WriteCancelled();

  5. #20
    Unregistered
    Guest
    No joy with that, same error.. I'll tidy & zip up the project and will post here

    Thanks for your time on this.


    P..

  6. #21
    Registered User
    Join Date
    Aug 2001
    Posts
    19
    Here it is. It contains the relevant code to show the problem.

    THX

  7. #22
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    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.

    public:
    static void WriteCancelled();

    should be replaced by

    public:
    void WriteCancelled();

    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

    CUserinfo3App::WriteCancelled();

    by

    theApp.WriteCancelled();


    This compiles fine.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #23
    Registered User
    Join Date
    Aug 2001
    Posts
    19
    Thats it!!

    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..


    P..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MSVC6 Debugger Question
    By Eber Kain in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2004, 07:40 PM
  2. MSVC6 appwizard generated code
    By person877 in forum Windows Programming
    Replies: 1
    Last Post: 07-28-2003, 02:22 PM
  3. Annoying MSVC6 Std bug
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-03-2002, 03:04 PM