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. C / C++ / MFC
  4. console to dialog

console to dialog

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
9 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.
  • U Offline
    U Offline
    User 2159113
    wrote on last edited by
    #1

    If I test a console program (client_server) and it can work. But how to use the source code into the dialog application because when I use the console source code into the dilog that I designed, it can not send the string that I want. Can tell me how to use it in the dialog application.

    C 1 Reply Last reply
    0
    • U User 2159113

      If I test a console program (client_server) and it can work. But how to use the source code into the dialog application because when I use the console source code into the dilog that I designed, it can not send the string that I want. Can tell me how to use it in the dialog application.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This question is impossible to answer. Any code in your console app will probably translate to a dialog app, but the key thing is to put it in the right place in an event driven system so that it's called when you want it to be. Without seeing the code, it's not possible to say more. 1983ttj wrote: it can not send the string that I want What does this even mean ? Christian Graus - Microsoft MVP - C++

      U 1 Reply Last reply
      0
      • C Christian Graus

        This question is impossible to answer. Any code in your console app will probably translate to a dialog app, but the key thing is to put it in the right place in an event driven system so that it's called when you want it to be. Without seeing the code, it's not possible to say more. 1983ttj wrote: it can not send the string that I want What does this even mean ? Christian Graus - Microsoft MVP - C++

        U Offline
        U Offline
        User 2159113
        wrote on last edited by
        #3

        Below is the code at the console application to send and receive: // Send and receive data. int bytesSent; int bytesRecv = SOCKET_ERROR; char sendbuf[300] = "Door Close"; char recvbuf[300] = ""; bytesRecv = recv( m_socket, recvbuf, 300, 0 ); prinf( "String Recv: %s\n", recvbuf ); bytesSent = send( m_socket, sendbuf, lstrlen(sendbuf), 0 ); printf( "String Sent: %s\n", recvbuf ); It will send a "Door Close" to server. I copy this into the dialog that to send "Door Close" when I click on that button, But I dont' know how to chage it so that it can send.

        C 1 Reply Last reply
        0
        • U User 2159113

          Below is the code at the console application to send and receive: // Send and receive data. int bytesSent; int bytesRecv = SOCKET_ERROR; char sendbuf[300] = "Door Close"; char recvbuf[300] = ""; bytesRecv = recv( m_socket, recvbuf, 300, 0 ); prinf( "String Recv: %s\n", recvbuf ); bytesSent = send( m_socket, sendbuf, lstrlen(sendbuf), 0 ); printf( "String Sent: %s\n", recvbuf ); It will send a "Door Close" to server. I copy this into the dialog that to send "Door Close" when I click on that button, But I dont' know how to chage it so that it can send.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Why would you have to change it ? The code has nothing to do with dialogs, or consoles. If it worked in the console app, and it's getting called in the dialog app, it should work there, too. Does the code compile ? Are you including the right header and lib files in your project ( if not, it won't compile ) ? Have you called WSAStartup ? Here[^] is the MSDN entry on the recv function, perhaps it can give you a clue what is in your console app, but you've failed to port to the dialog app ? I'm guessing you didn't write the console app ? Christian Graus - Microsoft MVP - C++

          U 1 Reply Last reply
          0
          • C Christian Graus

            Why would you have to change it ? The code has nothing to do with dialogs, or consoles. If it worked in the console app, and it's getting called in the dialog app, it should work there, too. Does the code compile ? Are you including the right header and lib files in your project ( if not, it won't compile ) ? Have you called WSAStartup ? Here[^] is the MSDN entry on the recv function, perhaps it can give you a clue what is in your console app, but you've failed to port to the dialog app ? I'm guessing you didn't write the console app ? Christian Graus - Microsoft MVP - C++

            U Offline
            U Offline
            User 2159113
            wrote on last edited by
            #5

            It works in console but when I compile at dialog it hang there. It can connect between server and client but when come to send and receive, it hang there. I already add the lib

            C 1 Reply Last reply
            0
            • U User 2159113

              It works in console but when I compile at dialog it hang there. It can connect between server and client but when come to send and receive, it hang there. I already add the lib

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Then there is code in the console app that's not being called in the dialog app, simple as that. I'd guess at the initialisation function I pointed out in my last post. Christian Graus - Microsoft MVP - C++

              U 1 Reply Last reply
              0
              • C Christian Graus

                Then there is code in the console app that's not being called in the dialog app, simple as that. I'd guess at the initialisation function I pointed out in my last post. Christian Graus - Microsoft MVP - C++

                U Offline
                U Offline
                User 2159113
                wrote on last edited by
                #7

                I already do the initialisation function that you pointed in last post which is WSAStartup. For the console, it is printf but for the dialog it is not printf right?

                B C 2 Replies Last reply
                0
                • U User 2159113

                  I already do the initialisation function that you pointed in last post which is WSAStartup. For the console, it is printf but for the dialog it is not printf right?

                  B Offline
                  B Offline
                  Bob Stanneveld
                  wrote on last edited by
                  #8

                  Hello, May I suggest an MFC tutorial or two? Try reading here[^] for a start. If you get stuck, google, MSDN and CodeProject are your friends. From what I read in your posts, your main problem is that your code is not properly structured. My guess is that you put almost everything in your main. Try and put all your code in classes: CClient and CServer for example. Doing this, enables you to reuse your code in a dialog app for example. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                  1 Reply Last reply
                  0
                  • U User 2159113

                    I already do the initialisation function that you pointed in last post which is WSAStartup. For the console, it is printf but for the dialog it is not printf right?

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    Like the other guy said, you're obviously lost at sea. Why would printf not work in a dialog app ? What were you using instead ? Christian Graus - Microsoft MVP - C++

                    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