Article View: borland.public.cppbuilder.nativeapi
Article #5866How to export a C++ object from DLL
From: sky
Date: Tue, 28 Jun 2005 03:34
Date: Tue, 28 Jun 2005 03:34
74 lines
2500 bytes
2500 bytes
Hi all
I'm developing a DLL with class in it.
but there are many questions when using C++ Object int the DLL
i.e.
1. vritual function can't be invoked in the inherit class
2. data member can't be accessed
the following is a simple sample
// class in DLL
//-------------------------------------
class Object;
class A
{
public:
virtual void Refresh() = 0;
protected:
std::vector<Object> ObjList;
};
class B : public A
{
public:
virtual void Refresh();
protected:
virtual void Set();
int m_nIndex;
int m_nNumObject;
};
void B::Set()
{
m_nIndex = 0;
m_nNumObject = 0;
// ...
}
void B::Refresh()
{
Set();
// ...
}
//
A *g_pB = NULL;
// DLLMAIN
case PROCESS_ATTACH:
if(!g_pB) g_pB = static_cast<B*>(new B());
// DLL export function:
extern "C" MYDLL_API void GetObjectB(B** pB)
{
*pB = g_pB;
}
//----------------------------------------------
there is a error when i invoke the Refresh() via
g_pB Pointer out of the DLL
the error occured when the Set() will be invoking
but if i remove the virtual keyword for Set()
it can be invoking successfully
but the error appears again when the Set() running
the error occered in line: m_nIndex = 0; when
I trace the Set() function
that is to say,
I can't access the data member of the class that
inherited from an abstract class.
Any hint will be great appreciated.
sky
Technical Details
Message-ID:
<42c0c61f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder.xsnews.nl!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeeder.wxs.nl!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6f086e2adea8beea,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "sky" <huangc@motic.com> From: "sky" <huangc@motic.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: How to export a C++ object from DLL Date: Tue, 28 Jun 2005 11:34:58 +0800 Lines: 76 Organization: ckhome X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 218.85.121.51 Message-ID: <42c0c61f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1119929887 218.85.121.51 (27 Jun 2005 20:38:07 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder.xsnews.nl!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeeder.wxs.nl!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail