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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can anyone help with my code???

Can anyone help with my code???

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studiowinforms
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Draco0283
    wrote on last edited by
    #1

    I am really new to C++ and I dont have a clue what Im doing yet. I keep reciving the following compiler error c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\Windows Forms\Form1.h(144): error C2065: 'hInstance' : undeclared identifier:confused: The code itself is listed below. If anyone can help me I would apprecaite it very much

    //////////Form1.h  
    #pragma once
    
    HWND hw;
             MSG  msg;
             int status;
    		 
    namespace WindowsForms
    {
        	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	///  
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the 
    	///          'Resource File Name' property for the managed resource compiler tool 
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// 
    	public __gc class Form1 : public System::Windows::Forms::Form
    	
    	{	
    
    		public:
    		Form1(void)
    		{
    			InitializeComponent();
    		}
      
    	protected:
    		void Dispose(Boolean disposing)
    		{
    			if (disposing && components)
    			{
    				components->Dispose();
    			}
    			__super::Dispose(disposing);
    		}
    	private: System::Windows::Forms::Button *  button1;
    	private: System::Windows::Forms::Button *  button3;
    	private: System::Windows::Forms::Button *  button4;
    	private: System::Windows::Forms::TextBox *  textBox1;
    
    
    	private:
    		/// 
    		/// Required designer variable.
    		/// 
    		System::ComponentModel::Container * components;
    
    		/// 
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// 
    		void InitializeComponent(void)
    		{
    			this->button1 = new System::Windows::Forms::Button();
    			this->button3 = new System::Windows::Forms::Button();
    			this->button4 = new System::Windows::Forms::Button();
    			this->textBox1 = new System::Windows::Forms::TextBox();
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Cursor = System::Windows::Forms::Cursors::Hand;
    			this->button1->ForeColor = System::Drawing::Color::Black;
    			this->button1->ImageAlign = 
    
    System::Drawing::ContentAlignment::TopCenter;
    			this->button1->Location = Sys
    
    M 1 Reply Last reply
    0
    • D Draco0283

      I am really new to C++ and I dont have a clue what Im doing yet. I keep reciving the following compiler error c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\Windows Forms\Form1.h(144): error C2065: 'hInstance' : undeclared identifier:confused: The code itself is listed below. If anyone can help me I would apprecaite it very much

      //////////Form1.h  
      #pragma once
      
      HWND hw;
               MSG  msg;
               int status;
      		 
      namespace WindowsForms
      {
          	using namespace System;
      	using namespace System::ComponentModel;
      	using namespace System::Collections;
      	using namespace System::Windows::Forms;
      	using namespace System::Data;
      	using namespace System::Drawing;
      
      	///  
      	/// Summary for Form1
      	///
      	/// WARNING: If you change the name of this class, you will need to change the 
      	///          'Resource File Name' property for the managed resource compiler tool 
      	///          associated with all .resx files this class depends on.  Otherwise,
      	///          the designers will not be able to interact properly with localized
      	///          resources associated with this form.
      	/// 
      	public __gc class Form1 : public System::Windows::Forms::Form
      	
      	{	
      
      		public:
      		Form1(void)
      		{
      			InitializeComponent();
      		}
        
      	protected:
      		void Dispose(Boolean disposing)
      		{
      			if (disposing && components)
      			{
      				components->Dispose();
      			}
      			__super::Dispose(disposing);
      		}
      	private: System::Windows::Forms::Button *  button1;
      	private: System::Windows::Forms::Button *  button3;
      	private: System::Windows::Forms::Button *  button4;
      	private: System::Windows::Forms::TextBox *  textBox1;
      
      
      	private:
      		/// 
      		/// Required designer variable.
      		/// 
      		System::ComponentModel::Container * components;
      
      		/// 
      		/// Required method for Designer support - do not modify
      		/// the contents of this method with the code editor.
      		/// 
      		void InitializeComponent(void)
      		{
      			this->button1 = new System::Windows::Forms::Button();
      			this->button3 = new System::Windows::Forms::Button();
      			this->button4 = new System::Windows::Forms::Button();
      			this->textBox1 = new System::Windows::Forms::TextBox();
      			this->SuspendLayout();
      			// 
      			// button1
      			// 
      			this->button1->Cursor = System::Windows::Forms::Cursors::Hand;
      			this->button1->ForeColor = System::Drawing::Color::Black;
      			this->button1->ImageAlign = 
      
      System::Drawing::ContentAlignment::TopCenter;
      			this->button1->Location = Sys
      
      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      Draco0283 wrote: #include "Form1.h" // <--- You use hInstance at here in this file. using namespace WindowsForms; int APIENTRY _tWinMain(HINSTANCE hInstance, // But hInstance actually is known by the compiler at this line... HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ /* */ } Maxwell Chen

      D 1 Reply Last reply
      0
      • M Maxwell Chen

        Draco0283 wrote: #include "Form1.h" // <--- You use hInstance at here in this file. using namespace WindowsForms; int APIENTRY _tWinMain(HINSTANCE hInstance, // But hInstance actually is known by the compiler at this line... HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ /* */ } Maxwell Chen

        D Offline
        D Offline
        Draco0283
        wrote on last edited by
        #3

        Ok in reference to Maxwell Chen I tried several things. I moved the #include "form.h" statement and I tried to move where it calls hInstance. Everything I did brought up more problems than before. Where should it go? Thanks for your help Draco

        J 1 Reply Last reply
        0
        • D Draco0283

          Ok in reference to Maxwell Chen I tried several things. I moved the #include "form.h" statement and I tried to move where it calls hInstance. Everything I did brought up more problems than before. Where should it go? Thanks for your help Draco

          J Offline
          J Offline
          Juergen Froehlich
          wrote on last edited by
          #4

          in form1.h you define in the class Form 1 the button3_Click method System::Void button3_Click(System::Object * sender, System::EventArgs * e) { BOOL CALLBACK DialogProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); hw = CreateDialog( hInstance , MAKEINTRESOURCE ( 102 ) ,NULL,reinterpret_cast(DialogProc )); } This has the parameter sender and e. Because no parameter hInstance is given as parameter into the method and also there is no class parameter with the name hInstance the parameter hInstance cannot be known to the compiler. Where shall it come from? In traditional Win32 SDK development this is given to the main function by windows when the application is started and normally will be kept as global variable in the ugly Win32 SDK style. Here you are in the object oriented world of .NET. Possible there are some method in the Form class allowing access to the application object, where one would typically search for the Win32 style instance handle. (I dont know where exactly). It should also work for this case to set NULL instead of the concrete hInstance value of the application.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

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