Solved

Export/import variables in/from a afx extension dll

Posted on 2004-10-20
9
354 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
Comment Utility
Thanks for any help.
Dennis
0
 
LVL 12

Expert Comment

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

Expert Comment

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

Author Comment

by:DennisWood
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

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

Accepted Solution

by:
BeyondWu earned 250 total points
Comment Utility
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
Comment Utility
Oops, I made a mistake, it should be
sField[0]="a";
sField[1]="b";
sField[2]="c";
0
 
LVL 9

Expert Comment

by:BeyondWu
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
Generic progress indicator 6 109
ORA-01403: no data found 43 82
noX challenge 17 75
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

10 Experts available now in Live!

Get 1:1 Help Now