Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
E

eastman75

@eastman75
About
Posts
6
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Error 2248: cannot access protected member declared in CWinapp
    E eastman75

    I've been trying to write into the registry some data not related to the application in case. As it happens CWinApp functions are not intended for such usage -- they are intended to write the registration data of the running application. In that case the correct usage is as follows: 1. Place call to the SetRegistryKey function in the "InitInstance". For example,

    BOOL DerivedApp::InitInstance()
    {
    // Standard initialization

    LPCTSTR lpszRegistryKey = "SomeSection" ;
    SetRegistryKey(lpszRegistryKey) ;
    . . .
    

    }

    2. Place call to the other necessary functions in the proper place of your application. For example,

    void SomeClass::OnStart()
    {
    . . .

    LPCTSTR lpszSection    = "SomeSection" ;
    LPCTSTR lpszStringItem = "SomeString" ;
        LPCTSTR lpszValue      = "SomeStringValue" ;
    if (!AfxGetApp()->;WriteProfileString(lpszSection, lpszStringItem, lpszValue))
    	AfxMessageBox("Registry settings weren't modified.") ;
        . . .
    

    }

    I've checked it -- it works. But not in the case if you have to write into the Registry some data not related to your application. Regards to all of you, chaps!

    C / C++ / MFC help c++ windows-admin

  • Error 2248: cannot access protected member declared in CWinapp
    E eastman75

    Hi, Albert, I'd tried various approaches until I found an excellent C++ Tutorial (http://www.learncpp.com/) and got the understanding that my problem is related to the inheritance subject. As it is clearly stated in the tutorial:

    1. The protected access specifier allows derived classes to directly access members of the base class while not exposing those members to the public.

    I see now that I have to make call within but my derived class. It does work except that there reveals another problem -- WriteRegisterString needs an access to the m_pszRegistryKey variable which is an attribute of CWinApp class. IAE, I have to learn a bit more on the subject. The discussion was very helpful and I thank you for the time you spent on it. Regards, Anatoly

    C / C++ / MFC help c++ windows-admin

  • Error 2248: cannot access protected member declared in CWinapp
    E eastman75

    Sorry, it doesn't work either. I do have a CWinApp derived class in my project (refer to my previous reply). It is a simple dialog application. I need to write to the registry some value and -- before using WriteProfileString -- I try to call SetRegistryKey. There is the code snippet:

    AfxGetApp()->SetRegistryKey(lpszRegistryKey);
    

    At compiling I got the following message:

    patchdlg.cpp(229) : error C2248: 'SetRegistryKey' : cannot access protected member declared in class 'CWinApp'

    which returns us to the beginning of the discussion. Is it possible to avoid that error at all? What is it there that I have overlooked?

    C / C++ / MFC help c++ windows-admin

  • Error 2248: cannot access protected member declared in CWinapp
    E eastman75

    Thanks, Albert, You are completely right and it was my fault. Indeed, my application has a CwinApp derived class which is called CPatchApp:

    class CPatchApp : public CWinApp
    {
    public:
    CPatchApp();
    ...
    }

    All I had to do then is to declare

    (CPatchApp *) pApp = AfxGetApp();

    and to use that pApp pointer to access protected SetRegistryKey function like:

    pApp->SetRegistryKey( LPCTSTR lpszRegistryKey );

    Instead I wrote

    (CWinApp *) pApp = AfxGetApp();

    C / C++ / MFC help c++ windows-admin

  • Error 2248: cannot access protected member declared in CWinapp
    E eastman75

    Sorry, Albert, I don't undersdand what you suggest. Suppose I derive an auxiliary class as follows:

    class CAux : public CWinApp
    {
    public:
    void SetRegistryKey(LPCTSTR lpszKey);
    };

    Then in some other place I make a call:

    CAux::SetRegistryKey("somekey");

    Trying to compile, I got the following message:

    error C2352: 'CAux::SetRegistryKey' : illegal call of non-static member function

    I don't understand how to avoid the access rights for the protected member function. Regards, Anatoly

    C / C++ / MFC help c++ windows-admin

  • Error 2248: cannot access protected member declared in CWinapp
    E eastman75

    I am new to C++ MFC programming and -- though I've read a lot concerning the subject -- none of recipes seems to work in my case. The snippet of code is as follows:

    void CPatchDlg::OnStart()
    {
    ...
    // Write the result into the Registry
    CWinApp* pApp = AfxGetApp() ;
    pApp->SetRegistryKey(lpszRegistryKey) ;
    }

    Function SetRegistryKey(lpszKey) is a protected member of CWinApp class and cannot be used directly:

    error C2248: 'SetRegistryKey' : cannot access protected member declared in class 'CWinApp'...

    Please, help me to work around the problem.

    C / C++ / MFC help c++ windows-admin
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups