We help IT Professionals succeed at work.
Get Started

Placing the text from buffer into textBox.

tatikor_143
tatikor_143 asked
on
213 Views
Last Modified: 2010-04-24
I have an application which accepts the connection and recieves the messages from the client and holds it in a character buffer and I have created a VC++ windows application form and created a text box for that.Now I wanted to reroute the messages that I received on the buffer to be displayed on the Text box.Please help me as I am new to .Net platform.Here is the complete code......

Here is the code for the VC++ windows application form.I have the server socket code here which accepts the connections and reads the data from the client and puts it in a buffer.Now I want to redirect this to a text box.

Please help me out in doing this.Its very urgent

         <<<<<<<<<<<Form1.h>>>>>>>>>>>>>

              #pragma once


namespace test1 {

     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>
     /// 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.
     /// </summary>
     public ref class Form1 : public System::Windows::Forms::Form
     {
     public:
          Form1(void)
          {
               InitializeComponent();
               //
               //TODO: Add the constructor code here
               //
          }

     protected:
          /// <summary>
          /// Clean up any resources being used.
          /// </summary>
          ~Form1()
          {
               if (components)
               {
                    delete components;
               }
          }
     private: System::Windows::Forms::TextBox^  textBox1;
     protected:

     private:
          /// <summary>
          /// Required designer variable.
          /// </summary>
          System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
          /// <summary>
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// </summary>
          void InitializeComponent(void)
          {
               this->textBox1 = (gcnew System::Windows::Forms::TextBox());
               this->SuspendLayout();
               //
               // textBox1
               //
               this->textBox1->Location = System::Drawing::Point(24, 12);
               this->textBox1->Multiline = true;
               this->textBox1->Name = L"textBox1";
               this->textBox1->Size = System::Drawing::Size(526, 601);
               this->textBox1->text = "hello World";
               this->textBox1->TabIndex = 0;
               //
               // Form1
               //
               this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
               this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
               this->ClientSize = System::Drawing::Size(572, 632);
               this->Controls->Add(this->textBox1);
               this->Name = L"Form1";
               this->Text = L"Form1";
               this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
               this->ResumeLayout(false);
               this->PerformLayout();

          }
#pragma endregion
      private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                   }
      private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
                   }

                                     
                                    
                  
      };
}

                            <<<<<<<<<main.cpp>>>>>>>>>

// test1.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
#include <winsock.h>
#include <stdio.h>

using namespace test1;  
SOCKET s;
WSADATA w;
HWND hwnd;
#define MY_MESSAGE_NOTIFICATION 1048;


[STAThreadAttribute]

int main(array<System::String ^> ^args)
{
      int iResult;
      char buffer[256];
      
      
      int error = WSAStartup (0x0101,&w);

      if (error)
      {
            return 0;
      }
 
      if(w.wVersion != 0x0101)
      {
            WSACleanup();
            return 0;
      }
 
       SOCKADDR_IN addr;  

       addr.sin_family = AF_INET;
       addr.sin_port = htons(4000);

       addr.sin_addr.s_addr = htonl(INADDR_ANY);

       s=socket(AF_INET ,SOCK_STREAM ,IPPROTO_TCP);

       if( s == INVALID_SOCKET)
       {
             return 0;
       }

      
     if(bind(s,(LPSOCKADDR)&addr ,sizeof (addr)) == SOCKET_ERROR)
       {
             return 0;
       }

      
     listen(s,5);
     

       accept(s,NULL,NULL);

       //
      // Enabling Windows XP visual effects before any controls are created
      Application::EnableVisualStyles();
      Application::SetCompatibleTextRenderingDefault(false);

      // Create the main window and run it
      //Form1 ^ h_Form1  = gcnew Form1();
      //h_Form1->textBox1//->Text = buffer;

      Application::Run(gcnew Form1());

      do {

        iResult = recv(s,buffer,sizeof(buffer), 0);
        if ( iResult > 0 )
            printf("Bytes received: %d\n", iResult);
        else if ( iResult == 0 )
            printf("Connection closed\n");
        else
            printf("recv failed: %d\n", WSAGetLastError());

    } while( iResult > 0 );

       return 1;
}




Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE