By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,226 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,226 IT Pros & Developers. It's quick & easy.

std::auto_ptr with virtual class

P: n/a
Hi all.
I have a class with virtual functions.
This class lives in DLL. In main program I use this class by obtaining
his pointer (by function that's exports from dll).

class CfromDLL
{
...
virtual int Foo();
...
};

CfromDLL* GetAPI();

I want use a std::auto_ptr (std::auto_ptr<CfromDLL> pnt) on this class.
And I get the linkers errors.
But if I use an explicit pointer (CfromDLL *pnt) - it's all right.
Why I have the linkers crash with auto_ptr ?

PS. Don't tell me about FAQ, because I can't go in Interet now.
Dec 25 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Marchello wrote:
Hi all.
[redacted]

PS. Don't tell me about FAQ, because I can't go in Interet now.


DLLs are beyond the scope of the Standard. And I will tell you about
the FAQ, because the only way to post to this group is to be on the Net.

Hint. The Internet is not just the web.
Dec 25 '05 #2

P: n/a
> DLLs are beyond the scope of the Standard.

But I did not ask anything about DLL.
And I will tell you about the FAQ, because the only way to post to this
group is to be on the Net.
No. It is no one way.
We have a several servers that's provides me to the news groups
and to the Net separately.
I can write here, but I can't see any web-pages.
Hint. The Internet is not just the web.

I know.
Dec 25 '05 #3

P: n/a
Hi

Marchello wrote:
Hi all.
I have a class with virtual functions.
This class lives in DLL. In main program I use this class by obtaining
his pointer (by function that's exports from dll).
(Elsewhere in the thread you say you haven't asked about dlls. Then why do
you mention them at all, if you know your problem has nothing to do with
dlls?)
class CfromDLL
{
..
virtual int Foo();
..
};

CfromDLL* GetAPI();

I want use a std::auto_ptr (std::auto_ptr<CfromDLL> pnt) on this class.
And I get the linkers errors.
What errors?
I'm sorry, the dust layer on my crystal ball is too thick...
Why I have the linkers crash with auto_ptr ?


It doesn't really crash, right?
Because otherwise you should really ask your compiler vendor...

Markus

Dec 25 '05 #4

P: n/a

Marchello wrote:
Hi all.
I have a class with virtual functions.
This class lives in DLL. In main program I use this class by obtaining
his pointer (by function that's exports from dll).

class CfromDLL
{
..
virtual int Foo();
..
};

CfromDLL* GetAPI();

I want use a std::auto_ptr (std::auto_ptr<CfromDLL> pnt) on this class.
And I get the linkers errors.
But if I use an explicit pointer (CfromDLL *pnt) - it's all right.
Why I have the linkers crash with auto_ptr ?

PS. Don't tell me about FAQ, because I can't go in Interet now.


Please post the linker error you're getting.

Dec 26 '05 #5

P: n/a
> Please post the linker error you're getting.

One of the errors:
error LNK2001: unresolved external symbol "public: virtual int __stdcall
CSound::IsStop(void)" (?IsStop@CSound@@UAGHXZ)

(CSound - is my class with virtual functions)

The errors occurs when I add declaration: std::auto_ptr<CSound> S;
Dec 26 '05 #6

P: n/a

"Marchello" <ma*******@rtf-15.ntu-kpi.kiev.ua> wrote in message
news:do**********@news.ntu-kpi.kiev.ua...
Please post the linker error you're getting.


One of the errors:
error LNK2001: unresolved external symbol "public: virtual int __stdcall
CSound::IsStop(void)" (?IsStop@CSound@@UAGHXZ)

(CSound - is my class with virtual functions)

The errors occurs when I add declaration: std::auto_ptr<CSound> S;

You should make sure that CSound class is exported by DLL code and imported
by EXE code.
Like this:
// file: Sound.h
....
#ifdef MY_DLL
#define MY_EXPORT_IMPORT __declspec(dllexport)
#else
#define MY_EXPORT_IMPORT __declspec(dllimport)
#endif
class MY_EXPORT_IMPORT CSound
{
public:
...
virtual int __stdcall IsStop();
...
};

In preprocessor settings for the DLL you should declare:
MY_DLL=1

In preprocessor settings for the EXE don't declare MY_DLL symbol at all.

Boris
Dec 26 '05 #7

P: n/a
> You should make sure that CSound class is exported by DLL code and
imported by EXE code.
Like this:
// file: Sound.h
#ifdef MY_DLL
#define MY_EXPORT_IMPORT __declspec(dllexport)
#else
#define MY_EXPORT_IMPORT __declspec(dllimport)
#endif
class MY_EXPORT_IMPORT CSound
{
public:
...
virtual int __stdcall IsStop();
...
};


Yes, I know it.
But I am doing this by the another way.

I include the sound.lib to my project by:
#pragma comment (lib, "sound.lib")

And use the import function to create the CSound object:
#define SND_API extern "C" __declspec (dllimport)
SND_API CSound* CreateSoundAPI();

If I write the next:
CSound *Sound;
Sound = CreateSoundAPI(); - it's all right.
But if I write:
std::auto_ptr<CSound> Sound; - I have the linker's errors.
Dec 26 '05 #8

P: n/a
Marchello wrote:
I include the sound.lib to my project by:
#pragma comment (lib, "sound.lib")

And use the import function to create the CSound object:
#define SND_API extern "C" __declspec (dllimport)
SND_API CSound* CreateSoundAPI();

If I write the next:
CSound *Sound;
Sound = CreateSoundAPI(); - it's all right.
But if I write:
std::auto_ptr<CSound> Sound; - I have the linker's errors.


std::auto_ptr calls CSound's destructor. Do you have the destructor and
and all functions it calls (like IsStop) defined?

Martin.
Dec 26 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.