Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help needed to fix warning C4251

Help needed to fix warning C4251

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kri5
    wrote on last edited by
    #1

    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?

    A J 2 Replies Last reply
    0
    • K Kri5

      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?

      A Offline
      A Offline
      Alexander M
      wrote on last edited by
      #2

      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! ;-)

      K 1 Reply Last reply
      0
      • A Alexander M

        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! ;-)

        K Offline
        K Offline
        Kri5
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • K Kri5

          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?

          J Offline
          J Offline
          jmkhael
          wrote on last edited by
          #4

          http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html[^] Papa while (TRUE) Papa.WillLove ( Bebe ) ;

          A 1 Reply Last reply
          0
          • J jmkhael

            http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html[^] Papa while (TRUE) Papa.WillLove ( Bebe ) ;

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Yes...saw that...but can't find how to use the same approach for the _ConnectionPtr for ADO...the declaration is way too complex.

            J 1 Reply Last reply
            0
            • A Anonymous

              Yes...saw that...but can't find how to use the same approach for the _ConnectionPtr for ADO...the declaration is way too complex.

              J Offline
              J Offline
              jmkhael
              wrote on last edited by
              #6

              What about using the pragma warning?? Papa while (TRUE) Papa.WillLove ( Bebe ) ;

              K 1 Reply Last reply
              0
              • J jmkhael

                What about using the pragma warning?? Papa while (TRUE) Papa.WillLove ( Bebe ) ;

                K Offline
                K Offline
                Kri5
                wrote on last edited by
                #7

                Yes ok, it will work...but it's not much of a solution now, is it? :doh:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups