Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Is there a way for me to call a function from an external application? For example I have a POS application and its functions are exported in DLL and one of the functions is addItem(param1...,param2...) which adds an item to list in the POS. Would it be possible to call that function from my program?
Posted
Updated 13-Jun-10 22:52pm
v2

Do you want to call an exported function from the DLL or externally call a function written in the POS applicaton?

Actually, it is possible to call a function from an EXE the same way that you call a function from a DLL.
The condition in both these cases is that the function must be exported.
So the DLL or EXE can export functions to be called externally.
The LoadLibrary API can be used to load both the DLL and the EXE.

The only thing to take note here is that the EXE binary will be mapped into the calling process.
It will not be called in the current running instance of the EXE.
If you want to call into a currently running process, the EXE will either need to be a COM EXE or you will need some other inter-process communication mechanism.
 
Share this answer
 
Comments
rodcarlocastillo 14-Jun-10 3:25am    
I want to call it into a currently running process. "inter-process communication mechanism" this is what i researching on right now. how do i do this? could i probably get the address of a specific function and pass it to my program? so i would call it using a function pointer? I've tried this with c++ and vb, with c++ is my DLL and where i call the DLL through VB. i pass my VB function as a parameter to my c++ DLL.
«_Superman_» 14-Jun-10 3:30am    
I still don't understand the problem completely.
So you have 1 DLL. Now do you have 1 EXE or 2 EXEs.

If you have only one, then you simply use LoadLibrary and GetProcAddress APIs from the EXE code to load and call the function in the DLL.
rodcarlocastillo 14-Jun-10 4:40am    
i have 1 DLL and 1 Exe. The Exe file gets its function from the DLL. What i want to achieve is to create another EXE that runs side by side with EXE 1.
For example: In the DLL there is a function "addItem(param1...,param2...)" that when a call the addItem function in my EXE2(my application) it executes it to the other EXE which is EXE1.
Basically there are 2 exe files that uses the DLL, EXE1 is the POS and EXE2 is my application.
thanks for the help so far!
«_Superman_» 14-Jun-10 4:44am    
Sure you can do this.
Just call LoadLibrary on the DLL from your application and then use GetProcAddress to get the address of the function to call.
If you want to share data between the POS and your application you can use shared segments or memory mapped files.
rodcarlocastillo 14-Jun-10 6:35am    
can i use GetProcAddress with an activex DLL made in vb? i got a null value loading activex dll
From what you've written in your comment to superman's answer you can't do what you want directly. There's no easy way of calling an arbitrary function in another process. You've got a couple of options:

- use something like COM or CORBA to forward the function call for you. It'll require changes to both processes code to do so though.

- roll your own IPC mechanism (sockets, named pipes, even memory mapped files) to forward the function call for you. Again you'd need to change both processes code.

- use DLL injection to get some arbitrary code loaded into the recieving process and install your IPC mechanism. The injected DLL could listen for messages and forward the call for you. You'd only have to change the calling process and implement the injected DLL. A big problem might be any security software sounding alarm bells as your code starts behaving like malware.

Cheers,

Ash
 
Share this answer
 
Comments
rodcarlocastillo 14-Jun-10 9:22am    
is there no way of doing this without altering the other application? i just want to trigger a function from a application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900