
December 25th, 2005, 05:55 PM
| | | 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. | 
December 25th, 2005, 06:05 PM
| | | Re: std::auto_ptr with virtual class
Marchello wrote:[color=blue]
> Hi all.
> [redacted]
>
> PS. Don't tell me about FAQ, because I can't go in Interet now.
>[/color]
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. | 
December 25th, 2005, 06:35 PM
| | | Re: std::auto_ptr with virtual class
> DLLs are beyond the scope of the Standard.
But I did not ask anything about DLL.
[color=blue]
> And I will tell you about the FAQ, because the only way to post to this
> group is to be on the Net.[/color]
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.
[color=blue]
> Hint. The Internet is not just the web.[/color]
I know. | 
December 25th, 2005, 07:55 PM
| | | Re: std::auto_ptr with virtual class
Hi
Marchello wrote:
[color=blue]
> 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).[/color]
(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?)
[color=blue]
> 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.[/color]
What errors?
I'm sorry, the dust layer on my crystal ball is too thick...
[color=blue]
> Why I have the linkers crash with auto_ptr ?[/color]
It doesn't really crash, right?
Because otherwise you should really ask your compiler vendor...
Markus | 
December 26th, 2005, 04:55 AM
| | | Re: std::auto_ptr with virtual class
Marchello wrote:[color=blue]
> 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.[/color]
Please post the linker error you're getting. | 
December 26th, 2005, 08:05 AM
| | | Re: std::auto_ptr with virtual class
> 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; | 
December 26th, 2005, 08:35 AM
| | | Re: std::auto_ptr with virtual class
"Marchello" <marchello@rtf-15.ntu-kpi.kiev.ua> wrote in message
news:doo7qp$471$1@news.ntu-kpi.kiev.ua...[color=blue][color=green]
>> Please post the linker error you're getting.[/color]
>
> 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;[/color]
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 | 
December 26th, 2005, 09:25 AM
| | | Re: std::auto_ptr with virtual class
> You should make sure that CSound class is exported by DLL code and[color=blue]
> 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();
> ...
> };[/color]
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. | 
December 26th, 2005, 07:55 PM
| | | Re: std::auto_ptr with virtual class
Marchello wrote:[color=blue]
> 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.
>[/color]
std::auto_ptr calls CSound's destructor. Do you have the destructor and
and all functions it calls (like IsStop) defined?
Martin. |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|