answersLogoWhite

0


Best Answer

You cannot invoke external program functions directly if that's what you mean. In order for two program to communicate with each other you need some kind of marshalling system. Since the only entry point that is directly available is your main function you could use command line switches to invoke specific functions in your program, but you cannot return anything useful to the calling program other than an integer. The other downside is that you must load and unload your program with each call. If that is adequate for your needs then its certainly a solution, albeit an elegant one.

A better approach is to make use of your operating system's message queue. This allows two separate programs to communicate with each other through their own message handlers. Thus program A can post a message instructing program B to invoke a certain function and the function can post a message back to program A with the result of that function. Of course both programs must be running, but there's nothing to stop program A from invoking program B with a command line switch containing program A's process ID, thus allowing program B to post a message to program A when it is ready to receive messages.

Of course an altogether better approach would be to place all the shared functions in a dynamically linked library that either program can load and call just as if those functions were statically linked within the program itself. If the programs themselves need to communicate with each other, message queues can be used for that purpose, but shared functionality should be kept entirely separate wherever possible.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you call a function from other program to your program in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the only function all C plus plus programs must contain?

Every C plus plus program that is a main program must have the function 'main'.


What is a main function in c plus plus?

It is the first function that gets called when the program is executed.


A c plus plus statement that invokes a function is known as?

...a function call.


What do you call an object function in c plus plus?

method


In c plus plus are local declarations visible to the function in a program?

If you declare a variable inside of any fuction (except main) it will not be available to other functions.


What is a primary function in C plus plus?

There is no such thing. You probably meant the main function. The main function is the only function that is required as it serves as the entry point of the program.


What is int86 function in c plus plus?

It is DOS-specific function in TurboC to call an interrupt. See the built-in help.


Where is the global declaration section of a c plus plus program?

Anything declared outside of a function is global.


What is the importance of functions in a c plus plus program?

Functions are very important in C++, as you can't write the simplest program to print hello without using a function. Overall you can say that function are building blocks of a C++ program. Functions can also be defined by the programmer to reduce program size.


How do you write a programm in c plus plus without using function main?

I don't think its possible. Every C++ program must at least have the main function.


Is a function call a form of branching in C plus plus?

No. A branch is akin to a goto statement in procedural programming. The code branches off to a new code segment, never to return. A function call is akin to a subroutine in structured programming. When the subroutine is finished, control is returned to the instruction immediately following the function call, just as if the function's code were inline expanded at the call site.


What are the general format of C plus plus program?

The format of a basic C++ program is as follows: First, you have your include statements. Next, you have your function prototypes, and class declarations. Then, you have your main function. This can be organized into small parts using whitespace characters. Finally, you have the definition of all the functions you call in the main function. Really, it's up to the individual programmer how most of the code is organized, but the above is a good structure if you're not absolutely sure what you're doing.