在 C++ 的实例之间共享对象DLL

发布于 2024-10-02 12:34:29 字数 519 浏览 4 评论 0原文

大家早上好,

如果标题不太清楚,请原谅我,我会尝试在这里解释更多:

我目前正在与 ASI 合作开发 VBS2。 VBS2 执行 VBS2 DLL 插件中的函数。我有自己的应用程序,我想用它来修改正在使用的插件中的变量,以更改 VBS2 正在执行的内容。我开始在 VBS2 程序运行时直接使用应用程序更改变量,尽管这可能很愚蠢。

当这不起作用时,我进行了测试,发现 VBS2 程序正在使用“消息”对象的不同实例(我在其中存储变量)与我的应用程序访问的实例不同。

我想做的是让我的应用程序访问 VBS2 访问的对象的同一实例。我已经尝试了一些

#pragma data_seg(".testseg")
Message msg;
void foo(...); //etc.
#pragma data_seg()

,但由于某种原因,仍然出现了两个正在使用的实例。

我非常感谢任何和所有的帮助,并补充说 C++ 对我来说是一门新语言,所以请保持温柔。 :)

谢谢, 中号

Good morning all,

Forgive me if the title is not too clear, I'll try to explain more here:

I am currently working with the ASI for VBS2. VBS2 executes functions from a VBS2 DLL plugin. I have my own application which I want to use to modify variables within that plugin whilst it is being used, to change what is being executed by VBS2. I began by, foolish as it may be, directly changing the variables with my application whilst the VBS2 program was running.

When this did not work I tested and found that the VBS2 program was using a different instance of the "message" object, in which I was storing the variable, to the one being accessed by my application.

What I would like to do is have my application access the same instance of the object being accessed by VBS2. I have experimented a bit with

#pragma data_seg(".testseg")
Message msg;
void foo(...); //etc.
#pragma data_seg()

but for some reason or another it still appears there are two instances being used.

I would greatly appreciate any and all help, and would add that C++ is a new language to me so please be gentle. :)

Thanks,
M

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云醉月微眠 2024-10-09 12:34:29

您需要使用链接器标志来告诉链接器将该段放置在可共享内存中。

请参阅 http://msdn.microsoft.com/en-us/library/ms933104。 aspx

我相信你需要

#pragma comment(linker, "/SECTION:.testseg,RWS")

在你的程序中添加类似的东西。
我不确定,这可能只能在 DLL 中工作......

You need to use linker flags to tell the linker to place that segment in sharable memory.

See http://msdn.microsoft.com/en-us/library/ms933104.aspx

I belive you need to add something like

#pragma comment(linker, "/SECTION:.testseg,RWS")

to your program.
I'm not sure, this may only work in a DLL...

多情癖 2024-10-09 12:34:29

如果我正确理解你想要什么,你不能使用标准 C/C++ 工具来做到这一点。您的程序和另一个程序位于不同的内存空间中,并且它们彼此完全隔离。如果您的程序具有管理权限,您可以尝试读取&使用 WriteProcessMemory() 写入另一个进程的内存空间:

http://msdn.microsoft.com/en-us/library/ms681674%28v=VS.85%29.aspx

但是,在该内存空间中找到正确的对象是一个问题。

目前尚不清楚您是否有该插件的来源。如果这样做,还可以使用其他进程间通信技术。不幸的是,没有什么比改变变量那么简单。

If I understand correctly what you want, you can't do this with standard C/C++ tools. Your program and the other program live in separate memory spaces and they are completely insulated from each other. If your program has administrative privileges, you can attempt to read & write the memory space of the other process using WriteProcessMemory():

http://msdn.microsoft.com/en-us/library/ms681674%28v=VS.85%29.aspx

But then there's a problem of finding the right object in that memory space.

It's not clear whether you have the source for the plugin. If you do, there are other interprocess communication techniques that can be utilised. None as simple as just changing the variable, unfortunately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文