0
votes

I am exporting a global variable from a dll using __declspec(dllexport) and importing the same in the client exe using __declspec(dllimport).

The global variable in the dll is being updated with time in a separate thread. I want to receive this updated data in my client .exe, but I am not getting it. What I get is the only initial value of the global variable every time I read the data using a timer in the client exe.

What is the explanation of such a behavior? and what can I do to achieve what I want to achieve? Is there an option without including get() and set() exported functions from the dll?

Here is the code that is exported from dll:

typedef struct{
    int iTotalQueues;
    int iCurrentQueue;
    wchar_t szQueueName[100];
}UPDATE_STATUS_DATA;

__declspec(dllexport) UPDATE_STATUS_DATA UpdateStatusData;

This structure members are updated in a loop for a long time. The updating code is in the dll itself.

Here is the code that is imported in the exe:

typedef struct{
    int iTotalQueues;
    int iCurrentQueue;
    wchar_t szQueueName[100];
}UPDATE_STATUS_DATA;

__declspec(dllimport) UPDATE_STATUS_DATA UpdateStatusData;

I am reading this data inside a timer response and not getting the updated values.

1

1 Answers

0
votes

The code in your question as you would expect when built into a simple test project. So, here are the two explanations that I can concoct:

  1. You are taking a copy of UpdateStatusData in your executable. And so the changes to the value of UpdateStatusData made in the DLL do not get reflected in the copy.
  2. Your DLL is, for some reason, not modifying the struct.