Help needed to fix warning C4251
-
I have a class exported from a DLL which has a member of type _ConnectionPtr. I am importing the ADO library in the DLL as follows:
#import "msado15.dll" no_namespace named_guids rename("EOF", "adoEOF")
The _ConnectionPtr is defined using the _com_ptr_t<..> template in the ADO library, and since the template definition is not exported I get the above warning when compiling. If I had a member of a simpler template type in the class, for e.g.:MyTemplate<int> my_member;
..it would just be a matter of exporting the 'instantiated' template definition in the class definition like this:class __declspec(dllexport) CParameters { public: .... protected: .... template class __declspec(dllexport) MyTemplate<int>; MyTemplate<int> my_param; };
However, i am at a loss on how to proceed with the _ConnectionPtr template definition. The warning i get from the compiler is as follows (m_pConn is the member, CParameters is the exported class):warning C4251: 'm_pConn' : class '_com_ptr_t<class _com_IIID<struct _Connection,&struct __s_GUID _GUID_00000550_0000_0010_8000_00aa006d2ea4> >' needs to have dll-interface to be used b y clients of class 'CParameters'
Otherwise, the thing compiles ok and the m_pConn is initialised properly as a connection, but i would like to iron out these warnings. Any ideas? -
I have a class exported from a DLL which has a member of type _ConnectionPtr. I am importing the ADO library in the DLL as follows:
#import "msado15.dll" no_namespace named_guids rename("EOF", "adoEOF")
The _ConnectionPtr is defined using the _com_ptr_t<..> template in the ADO library, and since the template definition is not exported I get the above warning when compiling. If I had a member of a simpler template type in the class, for e.g.:MyTemplate<int> my_member;
..it would just be a matter of exporting the 'instantiated' template definition in the class definition like this:class __declspec(dllexport) CParameters { public: .... protected: .... template class __declspec(dllexport) MyTemplate<int>; MyTemplate<int> my_param; };
However, i am at a loss on how to proceed with the _ConnectionPtr template definition. The warning i get from the compiler is as follows (m_pConn is the member, CParameters is the exported class):warning C4251: 'm_pConn' : class '_com_ptr_t<class _com_IIID<struct _Connection,&struct __s_GUID _GUID_00000550_0000_0010_8000_00aa006d2ea4> >' needs to have dll-interface to be used b y clients of class 'CParameters'
Otherwise, the thing compiles ok and the m_pConn is initialised properly as a connection, but i would like to iron out these warnings. Any ideas?It's not very useful to export classes with templates! You can fix the problem by creating a static library instead of a DLL. The compiler tells you that an application that wants to use the DLL has to know the definition of _com_ptr_t > to be able to use the class. A static library would be the best solution. Don't try it, just do it! ;-)
-
It's not very useful to export classes with templates! You can fix the problem by creating a static library instead of a DLL. The compiler tells you that an application that wants to use the DLL has to know the definition of _com_ptr_t > to be able to use the class. A static library would be the best solution. Don't try it, just do it! ;-)
Hi Alex...thanks for replying. The thing is this: the dll i am writing will be used by a service. If i link it statically, i would have to re-compile the service each time i change something in the dll, right? It's something i would like to avoid. The problem lies in the ADO template which i am using in my dll. If it was my template i would have found another way, however i'm not that flexible with ADO. Further feedback is welcome...!
-
I have a class exported from a DLL which has a member of type _ConnectionPtr. I am importing the ADO library in the DLL as follows:
#import "msado15.dll" no_namespace named_guids rename("EOF", "adoEOF")
The _ConnectionPtr is defined using the _com_ptr_t<..> template in the ADO library, and since the template definition is not exported I get the above warning when compiling. If I had a member of a simpler template type in the class, for e.g.:MyTemplate<int> my_member;
..it would just be a matter of exporting the 'instantiated' template definition in the class definition like this:class __declspec(dllexport) CParameters { public: .... protected: .... template class __declspec(dllexport) MyTemplate<int>; MyTemplate<int> my_param; };
However, i am at a loss on how to proceed with the _ConnectionPtr template definition. The warning i get from the compiler is as follows (m_pConn is the member, CParameters is the exported class):warning C4251: 'm_pConn' : class '_com_ptr_t<class _com_IIID<struct _Connection,&struct __s_GUID _GUID_00000550_0000_0010_8000_00aa006d2ea4> >' needs to have dll-interface to be used b y clients of class 'CParameters'
Otherwise, the thing compiles ok and the m_pConn is initialised properly as a connection, but i would like to iron out these warnings. Any ideas? -
http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html[^] Papa while (TRUE) Papa.WillLove ( Bebe ) ;
-
Yes...saw that...but can't find how to use the same approach for the _ConnectionPtr for ADO...the declaration is way too complex.