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
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. C++ CLR Windows Form Application (Printing to the Printer)

C++ CLR Windows Form Application (Printing to the Printer)

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++dotnettutorial
16 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.
  • L Lost User

    Thank You so much, but the msdn tutorial its throw me exception "Object Reference not set to an instance of an object" and not printing... aand code project tutorial its not c++ Windows form application, i think its c# .net. please help me if u can with your tutorial for c++ windows form...... thank you..

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #4

    eakteam wrote:

    Object Reference not set to an instance of an object

    Means you are using an object reference that has not been initialised; use your debugger to find out where, what and why. As to the rest, whether it is C#, VB.NET or C++/CLR, the basics are the same and the code samples in MSDN are given in all languages.

    Use the best guess

    L 1 Reply Last reply
    0
    • L Lost User

      eakteam wrote:

      Object Reference not set to an instance of an object

      Means you are using an object reference that has not been initialised; use your debugger to find out where, what and why. As to the rest, whether it is C#, VB.NET or C++/CLR, the basics are the same and the code samples in MSDN are given in all languages.

      Use the best guess

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #5

      THIS IS MY CODE AND VISUAL STUDIO DEBUGER SHOW : A first chance exception of type 'System.NullReferenceException' occurred in System.Drawing.dll

      #pragma once
      #using
      #using
      #using

      namespace Printing2 {

      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      using namespace System::Data;
      using namespace System::Drawing;
      using namespace System::Drawing::Printing;
      using namespace System::IO;
      
      
      /// /// 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 ref class Form1 : public System::Windows::Forms::Form
      {
      public:
      	Form1(void)
      	{
      		InitializeComponent();
      		//
      		//TODO: Add the constructor code here
      		//
      	}
      
      protected:
      	/// /// Clean up any resources being used.
      	/// 
      	~Form1()
      	{
      		if (components)
      		{
      			delete components;
      		}
      	}
      private: System::Windows::Forms::Button^  Button1;
      private: System::Windows::Forms::PrintDialog^  PrintDialog1;
      private: System::Drawing::Printing::PrintDocument^  document;
      protected: 
      
      private:
      	/// /// Required designer variable.
      	/// 
      	System::ComponentModel::Container ^components;
      

      #pragma region Windows Form Designer generated code
      /// /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      ///
      void InitializeComponent(void)
      {
      this->Button1 = (gcnew System::Windows::Forms::Button());
      this->PrintDialog1 = (gcnew System::Windows::Forms::PrintDialog());
      this->document = (gcnew System::Drawing::Printing::PrintDocument());
      this->SuspendLayout();
      //
      // Button1
      //
      this->Button1->Location = System::Drawing::Point(94, 106);
      this->Button1->Name = L"Button1";
      this->Button1->Size = System::Drawing::Size(75, 23);
      this->Button1->TabIndex = 0;
      this->Button1->Text = L"button1";
      this->Button1->UseVisualStyleBackColor = true;
      this->Button1->Click += gcnew System::Eve

      L 1 Reply Last reply
      0
      • L Lost User

        THIS IS MY CODE AND VISUAL STUDIO DEBUGER SHOW : A first chance exception of type 'System.NullReferenceException' occurred in System.Drawing.dll

        #pragma once
        #using
        #using
        #using

        namespace Printing2 {

        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;
        using namespace System::Drawing::Printing;
        using namespace System::IO;
        
        
        /// /// 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 ref class Form1 : public System::Windows::Forms::Form
        {
        public:
        	Form1(void)
        	{
        		InitializeComponent();
        		//
        		//TODO: Add the constructor code here
        		//
        	}
        
        protected:
        	/// /// Clean up any resources being used.
        	/// 
        	~Form1()
        	{
        		if (components)
        		{
        			delete components;
        		}
        	}
        private: System::Windows::Forms::Button^  Button1;
        private: System::Windows::Forms::PrintDialog^  PrintDialog1;
        private: System::Drawing::Printing::PrintDocument^  document;
        protected: 
        
        private:
        	/// /// Required designer variable.
        	/// 
        	System::ComponentModel::Container ^components;
        

        #pragma region Windows Form Designer generated code
        /// /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        ///
        void InitializeComponent(void)
        {
        this->Button1 = (gcnew System::Windows::Forms::Button());
        this->PrintDialog1 = (gcnew System::Windows::Forms::PrintDialog());
        this->document = (gcnew System::Drawing::Printing::PrintDocument());
        this->SuspendLayout();
        //
        // Button1
        //
        this->Button1->Location = System::Drawing::Point(94, 106);
        this->Button1->Name = L"Button1";
        this->Button1->Size = System::Drawing::Size(75, 23);
        this->Button1->TabIndex = 0;
        this->Button1->Text = L"button1";
        this->Button1->UseVisualStyleBackColor = true;
        this->Button1->Click += gcnew System::Eve

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #6

        Sorry, but I cannot guess where the problem occurs. You need to step through the code to find out what reference has not been set. Also use the stacktrace to see where was the last actual step in your code.

        Use the best guess

        L K 2 Replies Last reply
        0
        • L Lost User

          Sorry, but I cannot guess where the problem occurs. You need to step through the code to find out what reference has not been set. Also use the stacktrace to see where was the last actual step in your code.

          Use the best guess

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #7

          ok ok ... thank you so so much... i will see with myself where i did wrong... but anyway if u have time and without disturbing you, ill be very happy if u make a form for me just to print ot the prnter something when button clicked... it need just 5 minutes to do... anyway if u cant its oki.. Thank You for ur time.

          P 1 Reply Last reply
          0
          • L Lost User

            ok ok ... thank you so so much... i will see with myself where i did wrong... but anyway if u have time and without disturbing you, ill be very happy if u make a form for me just to print ot the prnter something when button clicked... it need just 5 minutes to do... anyway if u cant its oki.. Thank You for ur time.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #8

            We don't do this for people. Imagine how many requests we get from people wanting us to do this bit of work, or that bit of work for them. It's not just the writing of the code; you would need descriptions of what we added and why so that you can modify it for yourself.

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            L 1 Reply Last reply
            0
            • P Pete OHanlon

              We don't do this for people. Imagine how many requests we get from people wanting us to do this bit of work, or that bit of work for them. It's not just the writing of the code; you would need descriptions of what we added and why so that you can modify it for yourself.

              I was brought up to respect my elders. I don't respect many people nowadays.
              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #9

              ok i understand u very well... anyway my question take answer only here... so thank you so much. i will try harder with myself

              1 Reply Last reply
              0
              • L Lost User

                Sorry, but I cannot guess where the problem occurs. You need to step through the code to find out what reference has not been set. Also use the stacktrace to see where was the last actual step in your code.

                Use the best guess

                K Offline
                K Offline
                kklim
                wrote on last edited by
                #10

                We need serious help here! Appreciate any technical advise and sample codes. We are facing the same problem. My programmers are struggling for weeks to try to understand how to format and print a report in MFC (C++)? It is so simple in JAVA. Why is the MFC environment technically so difficult to format and print a report, which is the most common things (output a formatted report) that an application wants to do. It seems that each and every developer have to construct their own codes to format & print a report in MFC C++. Is there any relevant sample code (formatting and printing a report) that can be downloaded and modified?

                L 1 Reply Last reply
                0
                • K kklim

                  We need serious help here! Appreciate any technical advise and sample codes. We are facing the same problem. My programmers are struggling for weeks to try to understand how to format and print a report in MFC (C++)? It is so simple in JAVA. Why is the MFC environment technically so difficult to format and print a report, which is the most common things (output a formatted report) that an application wants to do. It seems that each and every developer have to construct their own codes to format & print a report in MFC C++. Is there any relevant sample code (formatting and printing a report) that can be downloaded and modified?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #11

                  kklim wrote:

                  My programmers are struggling for weeks

                  It took me less than a minute to find Printing with MFC Made Easy[^].

                  Veni, vidi, abiit domum

                  K 1 Reply Last reply
                  0
                  • L Lost User

                    kklim wrote:

                    My programmers are struggling for weeks

                    It took me less than a minute to find Printing with MFC Made Easy[^].

                    Veni, vidi, abiit domum

                    K Offline
                    K Offline
                    kklim
                    wrote on last edited by
                    #12

                    Richard, Thanks for your pointer. Very helpful indeed! Appreciate if we can also get your advise on how to print to a network (IP) printer? We are using HP laser printer, connected over a LAN.

                    L 1 Reply Last reply
                    0
                    • K kklim

                      Richard, Thanks for your pointer. Very helpful indeed! Appreciate if we can also get your advise on how to print to a network (IP) printer? We are using HP laser printer, connected over a LAN.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #13

                      It's exactly the same as printing to a local one.

                      Veni, vidi, abiit domum

                      K 1 Reply Last reply
                      0
                      • L Lost User

                        It's exactly the same as printing to a local one.

                        Veni, vidi, abiit domum

                        K Offline
                        K Offline
                        kklim
                        wrote on last edited by
                        #14

                        Thanks again. Somehow, we tried many times, but it does not work. Do we need to get the printer handler (or context of the printer) before we can output to it? If so, can what are the functions to do so?

                        L 1 Reply Last reply
                        0
                        • K kklim

                          Thanks again. Somehow, we tried many times, but it does not work. Do we need to get the printer handler (or context of the printer) before we can output to it? If so, can what are the functions to do so?

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #15

                          All printing in Windows goes through the same route and print data is passed to the printer drivers to be rendered onto the physical device. It does not matter whether the printer is parallel, USB, network, WiFi or Bluetooth, they all work in the same way. If you have problems with a specific device then you need to diagnose why it is not working.

                          Veni, vidi, abiit domum

                          K 1 Reply Last reply
                          0
                          • L Lost User

                            All printing in Windows goes through the same route and print data is passed to the printer drivers to be rendered onto the physical device. It does not matter whether the printer is parallel, USB, network, WiFi or Bluetooth, they all work in the same way. If you have problems with a specific device then you need to diagnose why it is not working.

                            Veni, vidi, abiit domum

                            K Offline
                            K Offline
                            kklim
                            wrote on last edited by
                            #16

                            Thank you so much, Richard. You have been most help in resolving our problems.

                            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