illegal call of non-static member function

This is a discussion on illegal call of non-static member function within the Tech Board forums, part of the Community Boards category; Hello All, I am working on managed C++/CLI to create class library (DLL), I have a problem with the source ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    40

    illegal call of non-static member function

    Hello All,

    I am working on managed C++/CLI to create class library (DLL), I have a problem with the source code in the form1 load event that I don't really get what it suppose to be mean. The error I get is: error C2352: 'Languages::Languages::Menu' : illegal call of non-static member function


    Form1 code:

    Code:
    private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) 
    Languages::Languages::Menu(this->MainMenu1);
    }


    Class Library:

    Code:
    #pragma once
    
    using namespace System;
    using namespace System::Windows::Forms;
    using namespace System::Collections;
    using namespace System::IO;
    using namespace System::Drawing;
    using namespace System::Runtime::InteropServices;
    
    
    namespace Languages {
    
      public ref class Languages
      {
    
    public: void Menu(Windows::Forms::MainMenu ^theMenu) {
          
          if (theMenu->MenuItems[0]->MenuItems[3]->MenuItems[0]->Checked == true)
          {
            theMenu->MenuItems[0]->MenuItems[3]->MenuItems[0]->Checked = true;
            theMenu->MenuItems[0]->MenuItems[3]->MenuItems[1]->Checked = false;
            theMenu->MenuItems[0]->MenuItems[3]->MenuItems[2]->Checked = false;
            theMenu->MenuItems[0]->MenuItems[3]->MenuItems[3]->Checked = false;
            theMenu->MenuItems[0]->MenuItems[3]->MenuItems[4]->Checked = false;
          }
        }
    
      };
    }

    Please can someone help???

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    90
    By calling Languages::Languages::Menu(), you're doing so without reference to a specific Languages::Languages object, i.e. in static context. The way it's currently defined, you would have to call it like this:

    Code:
    Languages::Languages mylang;
    mylang.Menu(this->MainMenu1);

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    40
    Thanks for your help Clairvoyant1332, I can see the problem is being fixed. Please could you help me with this as I have got an error.


    Code:
    mylangugages->SystemMenuinfo(MII, this->Handle);
    Error: C2664: 'Languages::Languages::SystemMenuinfo' : cannot convert parameter 2 from 'System::IntPtr' to 'int'


    Class Library:

    Code:
    public: void SystemMenuinfo(MENUITEMINFO ^menuinfotest, int hWindow) {
    		Microsoft::Win32::RegistryKey ^key1 = Microsoft::Win32::Registry::LocalMachine->OpenSubKey("Software\\MyApp\\Languages\\");
    		String ^value1 = nullptr;
    
    
    		if (key1 != nullptr)
    		{
    			value1 = (key1->GetValue("Test"))->ToString();
    		}
    
    		if (value1 == "French")
    		{
    			MENUITEMINFO ^MII = gcnew MENUITEMINFO();
    
    			int hMenu = GetSystemMenu(hWindow, 0);
    			MII->cbSize = Microsoft::VisualBasic::Strings::Len(MII);
    			String ^Text1 = nullptr;
    			MII->dwTypeData = "Restaurer";
    			MII->cch = MII->dwTypeData->Length;
    			MII->fMask = MIIM_STRING;
    			MII->wID = SC_RESTORE;
    			int RESTORE = SetMenuItemInfo(hMenu, MII->wID, false, MII);
    
    
    
    			MENUITEMINFO ^MII1 = gcnew MENUITEMINFO();
    
    			int hMenu1 = GetSystemMenu(hWindow, 0);
    			MII1->cbSize = Microsoft::VisualBasic::Strings::Len(MII1);
    			String ^Text2 = nullptr;
    			MII1->dwTypeData = "Bouger";
    			MII1->cch = MII1->dwTypeData->Length;
    			MII1->fMask = MIIM_STRING;
    			MII1->wID = SC_MOVE;
    			int MOVE = SetMenuItemInfo(hMenu1, MII1->wID, false, MII1);
    
    
    			MENUITEMINFO ^MII2 = gcnew MENUITEMINFO();
    
    			int hMenu2 = GetSystemMenu(hWindow, 0);
    			MII2->cbSize = Microsoft::VisualBasic::Strings::Len(MII2);
    			String ^Text3 = nullptr;
    			MII2->dwTypeData = "Taille";
    			MII2->cch = MII2->dwTypeData->Length;
    			MII2->fMask = MIIM_STRING;
    			MII2->wID = SC_SIZE;
    			int SIZE = SetMenuItemInfo(hMenu2, MII2->wID, false, MII2);
    
    
    			MENUITEMINFO ^MII3 = gcnew MENUITEMINFO();
    
    			int hMenu3 = GetSystemMenu(hWindow, 0);
    			MII3->cbSize = Microsoft::VisualBasic::Strings::Len(MII3);
    			String ^Text4 = nullptr;
    			MII3->dwTypeData = "Minimiser";
    			MII3->cch = MII3->dwTypeData->Length;
    			MII3->fMask = MIIM_STRING;
    			MII3->wID = SC_MINIMIZE;
    			int MINIMIZE = SetMenuItemInfo(hMenu3, MII3->wID, false, MII3);
    
    
    			MENUITEMINFO ^MII4 = gcnew MENUITEMINFO();
    
    			int hMenu4 = GetSystemMenu(hWindow, 0);
    			MII4->cbSize = Microsoft::VisualBasic::Strings::Len(MII4);
    			String ^Text5 = nullptr;
    			MII4->dwTypeData = "Maximiser";
    			MII4->cch = MII4->dwTypeData->Length;
    			MII4->fMask = MIIM_STRING;
    			MII4->wID = SC_MAXIMIZE;
    			int MAXIMIZE = SetMenuItemInfo(hMenu4, MII4->wID, false, MII4);
    
    
    			MENUITEMINFO ^MII5 = gcnew MENUITEMINFO();
    
    			int hMenu5 = GetSystemMenu(hWindow, 0);
    			MII5->cbSize = Microsoft::VisualBasic::Strings::Len(MII5);
    			String ^Text6 = nullptr;
    			MII5->dwTypeData = "Fermer  	      Alt+F4";
    			MII5->cch = MII5->dwTypeData->Length;
    			MII5->fMask = MIIM_STRING;
    			MII5->wID = SC_CLOSE;
    			int CLOSE = SetMenuItemInfo(hMenu5, MII5->wID, false, MII5);
    		}
    
    	}

    Do you know what variable that I need to make a change?

    Thanks,
    Mark
    Last edited by mark103; 04-17-2011 at 09:50 AM.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    90
    SystemMenuinfo is declared to take an int as the second parameter, but apparently the place where it's being called (which you didn't show) is passing in a System::IntPtr instead. I'm not familiar with these types, but I'm guessing something similar to an "int *".

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    40
    I doesn't show of the what? You didn't describe correctly with what I didn't show. I am calling systemmenuinfo in the form1 load event.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    90
    My mistake, I didn't see function call you quoted. You're passing in this->Handle as the second parameter but you don't show how Handle is declared. Based on the error message, I'm guessing it's declared as System::IntPtr. SystemMenuinfo is expecting an int as the second parameter, hence the error. Either change the datatype of the function parameter or pass in an int.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    This question is not native C++ but rather C++/CLI or managed C++. Moved to tech board for lack of a better place to put it.

  8. #8
    Registered User
    Join Date
    Apr 2011
    Posts
    40
    Okay no problem. So what do you expect me to make a change with?

    Post a example source code would be helpful.

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    It is not your fault it was in the wrong forum since we don't actually have a specific forum for this type of question. I, myself, am also using C++/CLI from time to time and so as C#'s and .NET's popularity and use grows I expect we will get more and more of these types of questions. I moved this to the tech board for lack of a better place at this time. I apologize if you took offense at my original post - it certainly was not meant in that manner.

    First, I do not recommend having a namespace and a class in that namespace share the same name.
    Second, you cannot call Languages::Menu() without an instance of Languages since Menu() is non-static.
    Third, System::IntPtr is the data type you would use to pass HWNDs HANDLEs and other Win32 native pointer types across the native/managed boundary.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-02-2008, 11:55 PM
  2. illegal call of non-static member function
    By JackR in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2007, 11:01 AM
  3. "illegal call of non-static member function"
    By Hulag in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2005, 07:44 AM
  4. Error: "illegal call of non-static member function"
    By Helix in forum Windows Programming
    Replies: 4
    Last Post: 12-31-2003, 09:01 PM
  5. Direct Music Illegal Static Member Call error
    By FwyWice in forum Game Programming
    Replies: 4
    Last Post: 11-30-2002, 04:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21