سؤال

Precondition

environment : VC2005

I encountered this problem when discovered circular dependency in my project(two dll references each other), so divide either of one dll to two dll's.

explain with example :

typedef struct { <br>
    char myFileName[MAX_PATH];
} MyStructure;

Before :

MyHeader.h

MyStructure globalStruct;

After:

MyCommon.h

#ifdef _MYGLOBAL_
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport)
#endif

API extern MyStructure globalStruct;

MyGlobal.c

API MyStructure globalStruct;

MySpecific.c

API MyStructure globalStruct;

failed code after changed: (this code run in specific dll)

handle = LoadLibrary(globalStruct.myFileName);

I confirmed globalStruct.myFileName values are same(at lease real words).

I can't access the value directly with debugger after changed. so, to see value in debugger, I copyed to temp local char[] variable. And then, I found before value and after value are different in tailing dummy char's.

before:
d:[my path] '0'(char end null) '0' '0' ... after:
d:[my path] '0'(char end null) '-3' '-3' '-3' ...

thank you for your reading.

هل كانت مفيدة؟

المحلول

self-solved my problem.

This is because dll does not re-compiled after my circular dependency removal work.

So, this problem is not related import/export global variable but dll re-compile issue.

Sorry for my ugly question.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top