Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

Export/import variables in/from a afx extension dll

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
DennisWood
Asked:
DennisWood
  • 3
  • 2
  • 2
  • +1
1 Solution
 
DennisWoodAuthor Commented:
Thanks for any help.
Dennis
0
 
OnegaZhangCommented:
Don't use CString, try LPCTSTR instead.
0
 
SteHCommented:
have you added putils.lib to the project for the other DLL?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
DennisWoodAuthor Commented:
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
 
SteHCommented:
What type is the other DLL using putils.dll?
0
 
BeyondWuCommented:
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
 
BeyondWuCommented:
Oops, I made a mistake, it should be
sField[0]="a";
sField[1]="b";
sField[2]="c";
0
 
BeyondWuCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now