Thread: returning string value

  1. #1
    Registered User vn1's Avatar
    Join Date
    Jun 2002
    Posts
    13

    Question returning string value

    Hi All,

    I try to write simply WinGUI dialog that collects user input and returns it to calling program. But I see that WinMain could return only int
    How can I return and get string (char) value?

    Any help will be appreciated
    Vaidotas.Vilnius.lt

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    When WinMain returns, it returns it's value to the operating system and terminates the program. The international C++ standard requires that your "main" returns an integer. If you want to return something other than that, I would suggest you have a design problem, or have not explained your question!

    Welcome, by the way, we do not get many visitors from the Baltic republics.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Just so you know, that 32-bit int returned from WinMain() is four bytes, and a pointer to a char array is also four bytes.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  4. #4
    Unregistered
    Guest
    johnnie2,

    thanks for your idea.
    But how to retain char array in memory to be available for calling program? I suppose to use ShellExecute or something like for calling...

    (Adrian, I know that my straightforward approach is bad, I just ask about ways usually applied)

  5. #5
    Registered User vn1's Avatar
    Join Date
    Jun 2002
    Posts
    13
    Sorry, Unregistered post was mine.
    Vaidotas.Vilnius.lt

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    As said
    >>If you want to return something other than that, I would suggest you have a design problem, or have not explained your question!

    a DLL would be better if you need a seperate interface. Send it the string to fill in.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    If you are working within a subprocess, you could probably use SendMessage() to send the contents of your string back to it's parent.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Davros
    Guest
    The simplest (and crudest) way of returning data from a program is to get the program to write the data into a temporary file before it terminates. The calling process can then read the file.

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> The simplest (and crudest)

    True of course, but then the writing program would need to tell the reading program that the data had been written. Messy - part written files, old files from previous runs, etc....

    Yup, can be done, but is not a real option in a rtue multitasking OS environment.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Elaborating on an earlier response, you could use FindWindow() to locate your parent window and send a WM_COPYDATA message, which apparently exists especially for this situation.

    Another possibility is the clipboard.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  11. #11
    Registered User vn1's Avatar
    Join Date
    Jun 2002
    Posts
    13
    Yes, thanks a lot, now I see - WM_COPYDATA message is right method when I have C++ or VB apps on both sides.

    Besides I wonder whether it's possible to write application which sends a message/string into VBScript? Maybe I should create COM Automation object for this purpose or can someone mention another way?
    Vaidotas.Vilnius.lt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM