For Programmers: Free Programming Magazines  


Home > Archive > VC Language > June 2005 > Export from DLL a COM Smart Pointer









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Export from DLL a COM Smart Pointer
Anand Choubey

2005-06-08, 4:02 pm

hi
i am writin a sime dll which uses a com smart pointer then visual c++ 6.0
gives 4521 warning. C++ Code snippet is

#import <DataStoreHelper.dll> no_namespace
class __declspec(dllexport) MyExportClass
{
//some public methods;
private:
IProcessedDataStorePtr m_pProcessData; //Smart pointer giving warning
};
compiler gives warning 4521 for m_pProcessData .
please tell me how to solve this problem.
--
With regards
thanks
Anand Choubey
Doug Harrison [MVP]

2005-06-08, 4:02 pm

On Wed, 8 Jun 2005 06:49:06 -0700, Anand Choubey wrote:

> hi
> i am writin a sime dll which uses a com smart pointer then visual c++ 6.0
> gives 4521 warning. C++ Code snippet is
>
> #import <DataStoreHelper.dll> no_namespace
> class __declspec(dllexport) MyExportClass
> {
> //some public methods;
> private:
> IProcessedDataStorePtr m_pProcessData; //Smart pointer giving warning
> };
> compiler gives warning 4521 for m_pProcessData .
> please tell me how to solve this problem.


You can either explicitly instantiate it and export the specialization, or
you can simply #pragma warning(disable:4251). Because the smart pointer is
a template, the compiler will instantiate it wherever it needs it, and
because you're very careful to use the same project settings for your DLL
and its clients, this is OK. BTW, you ought not to use
__declspec(dllexport) directly; instead, do it like this:

In some DLL header file, which the other DLL headers #include, write the
following, replacing "X" with the name of your DLL, making sure it has a
reasonable chance of being unique:

#ifdef COMPILING_X_DLL
#define X_EXPORT __declspec(dllexport)
#else
#define X_EXPORT __declspec(dllimport)
#endif

Then #define COMPILING_X_DLL only in that DLL's project. This method can be
used by multiple DLLs, and since the macro names are unique, they don't
conflict. Then you can do things like:

X_EXPORT void f();

class X_EXPORT MyClass
{
...
};

--
Doug Harrison
Microsoft MVP - Visual C++
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com