Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Export/import variables in/from a afx extension dll

Posted on 2004-10-20
9
364 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 147
Change owner from userA to server Local Administrators 7 66
wait notify demo infinite loop 3 121
NotAlone Challenge 20 84
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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