How to communicate beetwen parts of out-proc *.exe COM server?

250 views Asked by At

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"

0

There are 0 answers