如何在进程外 *.exe COM 服务器的各个部分之间进行通信?

发布于 2024-12-11 07:20:45 字数 1654 浏览 0 评论 0原文

我们有 *.exe 应用程序,它也是进程外 COM 服务器。

主线程正在执行一些网络例程:它接收数据包并将它们放入队列中。

COM客户端,例如VBA,使用COM服务器并且也想使用队列。尽管它们位于同一地址空间,但问题是:

我们如何为 COM 客户端提供与 exe 进程同时使用队列的机会。

有一个想法使用共享内存,但没有成功

UPD:

我尝试使用boost::interprocess。 由于相同的地址空间,我只想共享对象指针。

std::vector<int> //just example of MyType

exe部分:

main()
...
using namespace boost::interprocess;
struct shm_remove 
{
    shm_remove() { shared_memory_object::remove("SharedMemory"); }
    ~shm_remove(){ shared_memory_object::remove("SharedMemory"); }
} remover;

managed_shared_memory segment(open_or_create, "SharedMemory", 65536);
std::vector<int>** instance = segment.construct<std::vector<int>* >
   ("my_instance")  //name of the object
   ();            //ctor first argument
*instance = new std::vector<int>();
(*instance)->push_back(1);

// initialize the COM library
::CoInitialize(NULL);`enter code here`

COM部分:

HRESULT __stdcall CoMyCOMServer::Add(int *value)
{
cout << "Add()\n";

// this line goes out of debug, then VBA get error
managed_shared_memory segment(open_only, "SharedMemory"); 
std::vector<int>* *res = segment.find<std::vector<int>* > ("my_instance").first;
(*res)->push_back(*value);

return S_OK;
}

COM客户端(VBA)告诉

对象“IMyCOMServer”的方法“ADD”失败

Dim obj As IMyCOMServer
Set obj = CreateObject("MyCOMServer.object")   
obj.Add (2)

UPD2:

我刚刚用 try{}catch{} 包围了 Com 部分,并发现出现消息“找不到文件”的异常

We have *.exe application which is also out-process COM server.

The main thread is doing some network routine: it receives data packets and puts them into queue.

COM client, VBA for example, uses COM server and wants to use queue too. Despite the fact that they are in the same address space the question is:

How can we provide an opportunity for COM client to use the queue simultaneously with exe process.

There was an idea to use shared memory, but with no success

UPD:

I've tryed to use boost::interprocess.
Due to the same address space I've wanted just share object pointer.

std::vector<int> //just example of MyType

exe part:

main()
...
using namespace boost::interprocess;
struct shm_remove 
{
    shm_remove() { shared_memory_object::remove("SharedMemory"); }
    ~shm_remove(){ shared_memory_object::remove("SharedMemory"); }
} remover;

managed_shared_memory segment(open_or_create, "SharedMemory", 65536);
std::vector<int>** instance = segment.construct<std::vector<int>* >
   ("my_instance")  //name of the object
   ();            //ctor first argument
*instance = new std::vector<int>();
(*instance)->push_back(1);

// initialize the COM library
::CoInitialize(NULL);`enter code here`

COM part:

HRESULT __stdcall CoMyCOMServer::Add(int *value)
{
cout << "Add()\n";

// this line goes out of debug, then VBA get error
managed_shared_memory segment(open_only, "SharedMemory"); 
std::vector<int>* *res = segment.find<std::vector<int>* > ("my_instance").first;
(*res)->push_back(*value);

return S_OK;
}

COM client(VBA) tells

Method "ADD" of object "IMyCOMServer" failed

Dim obj As IMyCOMServer
Set obj = CreateObject("MyCOMServer.object")   
obj.Add (2)

UPD2:

I've just surrounded Com part with try{}catch{} and found out that the exception with the message "File not found"

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文