Solved

Export/import variables in/from a afx extension dll

Posted on 2004-10-20
9
366 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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