Solved

Export/import variables in/from a afx extension dll

Posted on 2004-10-20
9
358 Views
Last Modified: 2013-11-20
Hello Gurus,
I would like to export some variables from an AFX-Extension-DLL (PUTILS.DLL), and import them from another DLL. The export/import of functions and classes works fine.
I try it like this :

utils.h
====
AFX_EXT_CLASS CString sField[];

utils.c
====
CString sField={ "a", "b", "c" };

The compilation and linkage of PUTILS.DLL works fine. When I compile another DLL which uses sFieled, the compilation works, just the linker says unresolved external symbol
0
Comment
Question by:DennisWood
  • 3
  • 2
  • 2
  • +1
9 Comments
 

Author Comment

by:DennisWood
ID: 12364872
Thanks for any help.
Dennis
0
 
LVL 12

Expert Comment

by:OnegaZhang
ID: 12365174
Don't use CString, try LPCTSTR instead.
0
 
LVL 13

Expert Comment

by:SteH
ID: 12367164
have you added putils.lib to the project for the other DLL?
0
 

Author Comment

by:DennisWood
ID: 12367175
RE OnegaZhang :
The same happens with a single instance of size_t
RE SteH:
Yes I have, because the functions and classes exported by PUtils working fine.

It just does not work with global variables
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:SteH
ID: 12367242
What type is the other DLL using putils.dll?
0
 
LVL 9

Accepted Solution

by:
BeyondWu earned 250 total points
ID: 12367244
Your code seems not correct, here is the problem
utils.h
====
AFX_EXT_CLASS CString sField[];       // You defined a sField[] variable in utils.h, it's actually just a pointer CString* sField, just a definition, a symbol, at that time there no any really vaiable has been created. That's why the linker will report the unresolved external symbol error.

utils.c
====
CString sField={ "a", "b", "c" };          // You redefined another variable, it's name is sField, I even don't think you can pass the compiling. anyway it's another varaible, it has nothing to do with the AFX_EXT_CLASS CString sField[]; Even if you change it like this: CString sField[]={ "a", "b", "c" };

So, you can do like this:
utils.h
AFX_EXT_CLASS CString sField[3];   // You need to definitely tell compiler the size of your array, you can initailize it as this: CString sField[] = {"a", "b", "c"}, but if you want to separate the definition and initialization, you need to do this...

utils.c
YOu need to initailize your code like this, or use the for loop. Same reason, because you separated the definition and initialization, you have to do like this.
sField[1]="a";
sField[2]="b";
sField[3]="c";

Now, everything is ready for using in your another exe file

Good Luck
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 12377154
Oops, I made a mistake, it should be
sField[0]="a";
sField[1]="b";
sField[2]="c";
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 12563206
Dan & DennisWood,

I can sure I have answered this question. You can test it on your own machine, if it doesn't work please tell me.

regards,
Wu
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 122
List out all word 7 254
method notes when mouse over in eclipse 5 82
has22 challenge 11 78
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now