From: bucher on
Hi,

I have a function exported from dll.
Here is the declaration:

typedef struct tagPolicyBufEntry{
char* pPolicyBuf;
int iSize;
}POLICYBUFENTRY;
extern "C" _declspec(dllexport) DWORD
DBIPolicy_QueryPolicyListByHosts(const int iPolicyType, const CArray<int,
int&>& iHostIDList, map<int, POLICYBUFENTRY>& policyList);

I called it in another DLL named Policy_GetUSBDenyPolicy, here is the code:
map<int, POLICYBUFENTRY> policyBufList;
CArray<int, int&> iHostIDList;
typedef DWORD (*lpDBIPolicy_QueryPolicyListByHosts)(const int iPolicyType,
const CArray<int, int&>& iHostIDList, map<int, POLICYBUFENTRY>& policyList);
lpDBIPolicy_QueryPolicyListByHosts pDBIPolicy_QueryPolicyListByHosts =
(lpDBIPolicy_QueryPolicyListByHosts)(GetProcAddress(hDllPolicy,
"DBIPolicy_QueryPolicyListByHosts"));
dwError = pDBIPolicy_QueryPolicyListByHosts(DBOPT_USBDENYPOLICY,
iHostIDList, policyBufList);


I found the value of policyBufList._Tr._Nil is not NULL in
"Policy_GetUSBDenyPolicy". But after I switched the context to
"DBIPolicy_QueryPolicyListByHosts", the value of policyBufList._Tr._Nil was
changed to NULL immediately. And the address of this member value was
changed after context switch. This is very strange. Because the parameter
was passed by reference. And I have checked the project settings, I set both
dlls to "/Zp1 /MD".

Why the value changed after context switch? Thanks in advanced.


Bucher




From: bucher on
Sorry, I misunderstanded the mean of context switch. What I want to ask is
why value changed after call stack switch.



From: Igor Tandetnik on
"bucher" <bucher(a)xxxx.com> wrote in message
news:epRk22bsIHA.2068(a)TK2MSFTNGP05.phx.gbl
> I found the value of policyBufList._Tr._Nil is not NULL in
> "Policy_GetUSBDenyPolicy". But after I switched the context to
> "DBIPolicy_QueryPolicyListByHosts", the value of
> policyBufList._Tr._Nil was changed to NULL immediately.

_Nil is a static data member. Each module (in your case, the EXE and the
DLL) have its own separate copy of it. You are confusing yourself when
you access it as if it were a regular data member, part of the map
object you pass as a parameter: it's not.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: Igor Tandetnik on
"Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message
news:%233vS2fcsIHA.3716(a)TK2MSFTNGP04.phx.gbl
> "bucher" <bucher(a)xxxx.com> wrote in message
> news:epRk22bsIHA.2068(a)TK2MSFTNGP05.phx.gbl
>> I found the value of policyBufList._Tr._Nil is not NULL in
>> "Policy_GetUSBDenyPolicy". But after I switched the context to
>> "DBIPolicy_QueryPolicyListByHosts", the value of
>> policyBufList._Tr._Nil was changed to NULL immediately.
>
> _Nil is a static data member. Each module (in your case, the EXE and
> the DLL) have its own separate copy of it. You are confusing yourself
> when you access it as if it were a regular data member, part of the
> map object you pass as a parameter: it's not.

Do you use VC6, by any chance? If so, see

http://www.dinkumware.com/vc_fixes.html

"Fix to <xtree>" section. While you are at it, you may want to apply all
the other fixes (or just switch to a modern version of VC compiler).
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925