473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

std::auto_ptr with virtual class

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
8 2632
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
> 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
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

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
> 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

"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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SerGioGio | last post by:
Hello ! When a ref. counted smart pointer (template) class is available (like boost::shared_ptr), is there any (semantic) reason to still use std::auto_ptr rather than this smart pointer ? Or...
2
by: Jamie Burns | last post by:
Hello, I am trying to write some threadsafe code. I am using mutexes to restrict access to certain class members. Consider the method below: // begin code nippet bool...
9
by: BekTek | last post by:
How do you think? and why?
10
by: ma740988 | last post by:
Part of my confusion here is certainly my ignorance of templates and std::auto_ptr. Two topics, I've perused but need to really _delve_ into. In any event, consider the 'test' source. #...
20
by: Bronek Kozicki | last post by:
Hi Please try this code. I think that it's perfectly legal. However when compiled under MSVC71 stack overflow happens in first line of main, thus second line is never executed. B.
1
by: Guido Forthofer | last post by:
Hello, I convert my VC6 C++ project after VC7 (7.1) and have now an compiler error d:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\vector(810): error C2558: class...
10
by: dragoncoder | last post by:
Hi all, I am trying to understanding std::auto_ptr<Tclass implementation from "The C++ standard library" by Nicolai Josuttis. He gives a sample implementation of auto_ptr class template in...
7
by: j.l.olsson | last post by:
Hello, I am using std::auto_ptr to try to keep ownership of resources straight. However, I became aware that exception objects must provide a copy constructor, which made me uncertain of the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.