Search code examples
c++dllpragma

Sharing an object between instances of a C++ DLL


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


Solution

  • 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...