この質問が以前に回答されている場合は申し訳ありません。ただし、同様の質問はすべて、DLL 内のグローバル変数または静的変数とそれらの共有に関連しているようです。
2 つの個別のアプリケーション間で dll の 1 つのインスタンスを共有することは可能ですか?
2 つのアプリケーション (appA、appB) と DLL (theDLL) があります。
appA が theDLL の関数を呼び出して、ヒープ上に変数を作成し、それを theDLL に格納できるかどうかを確認しています。後で、appB を theDLL に接続して、以前に作成した変数にアクセスできるようにしたいと考えています。繰り返しますが、この回答が dll の静的およびグローバル変数と同じである場合は申し訳ありません。
ここにいくつかの疑似コードがあります:
(DLL)
class VariableHolder
{
public:
void StoreVariable(int x)
{
mInt = new int(x);
}
int GetVariable()
{
return mInt;
}
private:
int mInt;
}
(アプリA)
int main()
{
...
(assuming we got access to a VariableHolder singleton created in theDLL)
theVarialbeHolder.StoreVariable(5);
...
}
(appB)
int main()
{
...
(assuming we got access to a VariableHolder singleton created in theDLL)
if (theVarialbeHolder.GetVariable() == 5)
{
cout << "Hurray, how did you know?";
}
...
}