Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export instance of class into dll

Posted on 1998-07-09
8
Medium Priority
?
326 Views
Last Modified: 2010-04-10
I want to export global variable that is instance of some class into dll. I have tried usual technique:
 __declspec(dllexport) CMyClass MyInst; // declaration in .exe
 __declspec(dllimport) CMyClass MyInst; // declaration in .dl
but I get link error (error LNK2001: unresolved external symbol "class CMyClass  MyInst").
If I try do the same with simple type ( like int or void* ) it succedes. Is it possible to export
instance of class into dll and if it is - how?
Thanx for any help.
Platform: VC5/NT4 ( not using MFC )
0
Comment
Question by:tulin
[X]
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
  • 5
  • 2
8 Comments
 
LVL 8

Expert Comment

by:trestan
ID: 1167506
From the error message, it seems that you did not include the file contain the class, did you?
0
 
LVL 22

Accepted Solution

by:
nietod earned 210 total points
ID: 1167507
Yes it is possible, but the class must be exported as well as the instance.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167508
for exmple you could have

class __declspec(dllexport) SomeClass
{
};

__declspec(dllexport) SomeClass  SomeObject;

Are you familiar with exporting classes?
0
Technology Partners: 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!

 
LVL 22

Expert Comment

by:nietod
ID: 1167509
trestan may be closer to the problem than I.  (what I said is right, but it might not be your problem.)  As he said, the partcular error you get seems to suggest that you are not linking with the file that has the exported object.  (If that is the problem, you should reject my answer so he can get the points.)
0
 
LVL 1

Author Comment

by:tulin
ID: 1167510
Nietod is right, and I will give him the points, in spite of that I had some more
problems.
  Now, using the opportunity, does anybody know how can I do opposite thing -
in dll I want to see variable is defined outside in exe, this means to export variable
FROM exe TO dll.
  If you know, but want points, just write.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167511
Let me just confirm the question first
The EXE uses the DLL, but the EXE has an export (function or data, it doesn't matter) that the DLL needs to import.  Is that right?

If so it can be done, but is a bit of a pain.  If there are just one or two exports in the EXE that the DLL needs to know about, I would recomend that you have the EXE "register" the function or data with the DLL by passing a pointer to the functions or data to some procedure in the DLL.  This is likely to be a lot easier for you.  

If you want to do it the other way, let me know and I'll look it up.  (Its somewhere in the VC help, I read it long ago, because I thought I was going to have to use it but got around it.)
0
 
LVL 1

Author Comment

by:tulin
ID: 1167512
You understood question right.
I will try to avoid "a bit of pain"; if I still will need this, I will ask new question.
Thank you.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167513
feel free to ask here if you want.  it should only take me 10 minutes or so to find it.  I just didn't think it was worth 10 minutes if there was an easier solution that is in many ways better.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

636 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