控制另一个应用程序 [英] Controlling another application

查看:105
本文介绍了控制另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否可以从外部应用程序调用函数?例如,我有一个POS应用程序,其功能以DLL导出,其中一个功能是addItem(param1 ...,param2 ...),可在POS中添加一个项目到列表中.是否可以从我的程序中调用该函数?

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?

推荐答案

您要从DLL调用导出的函数还是从外部调用用POS应用程序编写的函数? ?

实际上,可以从EXE调用函数,就像从DLL调用函数一样.
这两种情况的条件都是必须导出函数.
因此,DLL或EXE可以导出要在外部调用的函数.
LoadLibrary API可用于加载DLL和EXE.

唯一需要注意的是EXE二进制文件将映射到调用进程中.
不会在EXE的当前运行实例中调用它.
如果要调用当前正在运行的进程,则EXE将需要是COM EXE,或者将需要其他一些进程间通信机制.
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.


从您所拥有的在您对超人答案的评论中写的您不能直接做您想做的事.没有简单的方法可以在另一个进程中调用任意函数.您有两种选择:

-使用COM或CORBA之类的东西为您转发函数调用.不过,这将需要更改两个流程的代码.

-滚动您自己的IPC机制(套接字,命名管道,甚至是内存映射文件)为您转发函数调用.同样,您需要更改两个流程代码.

-使用DLL注入将一些任意代码加载到接收过程中,并安装IPC机制.注入的DLL可以侦听消息并为您转发呼叫.您只需更改调用过程并实现注入的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


这篇关于控制另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆