CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2006
    Posts
    1

    Invoke a function from another running program (EXE) in C/C++

    i have a doubt in C++. lets asume A.exe is running and it has two functions A() and B(). i have another program B.exe, which needs to call some functions say A() in A.exe (which is already running).

    how can we achieve this, what concept we need to use??

    if u have some sample code, or tutorial or forums link, give me those reference.

  2. #2
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: Invoke a function from another running program (EXE) in C/C++

    If I am understanding your question correctly, you are talking about interprocess communication.

    If this is the case, then yes it is possible. Well, to an extent anyways.

    I don't know about calling functions of another process, but you could set up process pipe to communicate information back and forth to the programs.

    So, A.exe could be on the receiving end of this pipe and reading from it.
    B.exe could be on the sending end of this pipe, writing to it.

    If A.exe reads some data sent through the pipe by B.exe, it might execute some function or do something, depending on what you want it to do.

    Likewise, the situation could be reversed, and A.exe could also send data back to B.exe through the pipe, and B.exe could execute some function or do something special depending on the data it reads.

    In Unix/Linux, a pipe can be created by redirecting the stdout/stdin using the pipe() system command. I am not sure how to do this in windows.

    Check your Unix/Linux man pages for more information on pipe()
    Please rate my post if you felt it was helpful

  3. #3
    Join Date
    Jun 2004
    Location
    India
    Posts
    432

    Re: Invoke a function from another running program (EXE) in C/C++

    You are talking about 'Remote Procedure Calls' (RPC) OR remoting to be exact.

    RPC is not something that I can explain over a forum post. I go back to books to learn about RPC. Both Unix and Windows supoprt RPC. In Windows things such as COM or .NET remoting are easier to use than plain vanilla RPC. Then there is CORBA in Unix. They all originate from RPC concepts.

    COM/CORBA concepts are basically like this

    1. The exe, known as server, that wants its functions to be callable from other exe, known as client, specifies its exposed 'Interface' (functions) in a particular format such as IDL files.
    2. The client exe can read the IDL file and 'know' how to call that remote function.
    3. The client basically has to send the function data in a packet, using some kind of IPC, and receive back the reply in a data packet. This is called marshalling and unmarshalling.
    4. Then there is a lot of plumbing underneath, which helps with server discovery, server launch, marshalling, type libraries etc.
    Say no to supplying ready made code for homework/work assignments!!

    Please rate this post!

  4. #4
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: Invoke a function from another running program (EXE) in C/C++

    CORBA is not UNIX specific, it is platform independent and multi-language. One popular free open-source version of CORBA is ACE/TAO.

    In order for these mechanisms to work, the server must have been written to allow client connections.

    If you have an ordinary 3rd party GUI application that was not written specifically with a programming interface for computers, it may still be possible to get a computer to operate it as a robot, by generating the events that a human might generate. I say "possible" because it can be done but it is not straightforward.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured