Thread: Returning a string to another process

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    34

    Question Returning a string to another process

    Hello,

    I have a program package for making HMI (Human-Machine Interface) systems (for industrial use), which includes a fairly primitive (it actually supports semaphores, internal multithreading among other things, not pointers and data structures, though) built in programming language. I want to expand its functionallity by writing a DLL (yes, I am able to make DLL calls from it) that opens a Windows window (WinAPI) and lets the user do various things. When the user is done, I want to return data from the DLL to my HMI system. When returning a single integer, this shouldn't be a problem, but, sometimes I want to return a string of characters or even several integers. Is this possible to do? I'm not too experienced with such programming, and I'm only at a learning stage, so any suggestions, examples, explanations of why or why not this will work are greatly appreciated! :-)

    Thanks,
    Eirik

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I would think you should be able to do this. Instead of passing back a rc=0, pass back the pointer to your malloc()'ed storage where you put your message. Have the HMI free() it when finished with it.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Dino View Post
    I would think you should be able to do this. Instead of passing back a rc=0, pass back the pointer to your malloc()'ed storage where you put your message. Have the HMI free() it when finished with it.
    That is, if it's actually C...
    But since a DLL is always loaded into the client process memory, they share they same virtual memory, so anything that is created inside the DLL - via dynamic allocation or something else - will also exist in the client, so passing pointers and references will be fine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I didn't read the question or any of the answers....

    GlobalAlloc() is the correct way to do this.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I didn't read the question or any of the answers....
    Then how could you possibly contribute to anything other than your post count?

    >> GlobalAlloc() is the correct way to do this.
    If you're implying that the memory returned from GlobalAlloc is sharable across process boundaries, then that's just incorrect.
    If you're referring to not using malloc() in one module, and free() in another (because that's bad) then that's correct - and using GlobalAlloc() is one away around that. Another option is to have a FreeData() interface in your DLL so that the same module that did the allocation can also do the de-allocation.
    http://blogs.msdn.com/oldnewthing/ar...15/755966.aspx

    gg

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    34
    Thank you guys for all the answers, I'll do some fiddelin' and see what I can work out :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 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