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. ATL / WTL / STL
  4. Struct with Vector<BYTE> size different in VS2013

Struct with Vector<BYTE> size different in VS2013

Scheduled Pinned Locked Moved ATL / WTL / STL
visual-studiocomgraphicsalgorithmshelp
13 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.
  • J Offline
    J Offline
    Jacobkingsly
    wrote on last edited by
    #1

    I have the following structure defined inside my DLL and a COM component we developed. struct ContentStr { ContentStr():ptr(NULL), contSize(0), structSize(0), X(0), Y(0){} const BYTE* ptr; int contSize; int structSize; //output std::vector m_v_Data; int X; int Y; private: ContentStr ( const ContentStr & rhs ); ContentStr & operator= ( const ContentStr & rhs ); }; The COM component invokes a DllExport method in the DLL which accepts the structure as reference and fills its value. It was working fine in VS2008. Recently I ported my code base to VS2013. Now the method throws exception when invoked. When I checked the size of the structure using sizeof operator, I was surprised a bit. VS 2008: /*Inside COM*/ sizeof(ContentStr) = 40 /*Inside DLL*/ sizeof(ContentStr) = 40 VS 2013: /*Inside COM*/ sizeof(ContentStr) = 36 /*Inside DLL*/ sizeof(ContentStr) = 32 I could see that the difference in size is due to the difference in vector size. Searching the internet gave me huge confusion hence I am posting this question on the expert forum. Could someone please explain me why is this difference seen in the sizes and help me find a solution.

    Kings

    L S V J 4 Replies Last reply
    0
    • J Jacobkingsly

      I have the following structure defined inside my DLL and a COM component we developed. struct ContentStr { ContentStr():ptr(NULL), contSize(0), structSize(0), X(0), Y(0){} const BYTE* ptr; int contSize; int structSize; //output std::vector m_v_Data; int X; int Y; private: ContentStr ( const ContentStr & rhs ); ContentStr & operator= ( const ContentStr & rhs ); }; The COM component invokes a DllExport method in the DLL which accepts the structure as reference and fills its value. It was working fine in VS2008. Recently I ported my code base to VS2013. Now the method throws exception when invoked. When I checked the size of the structure using sizeof operator, I was surprised a bit. VS 2008: /*Inside COM*/ sizeof(ContentStr) = 40 /*Inside DLL*/ sizeof(ContentStr) = 40 VS 2013: /*Inside COM*/ sizeof(ContentStr) = 36 /*Inside DLL*/ sizeof(ContentStr) = 32 I could see that the difference in size is due to the difference in vector size. Searching the internet gave me huge confusion hence I am posting this question on the expert forum. Could someone please explain me why is this difference seen in the sizes and help me find a solution.

      Kings

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I don't see how std::vector m_v_Data; will compile; vector is a template class and needs a type to define it. [edit] In VS2010 I get 20 for the size of a vector<int>, and in VS2013 I get 16. There must be some other difference in your DLL code that reduces the total by another 4 bytes. [/edit]

      J 1 Reply Last reply
      0
      • J Jacobkingsly

        I have the following structure defined inside my DLL and a COM component we developed. struct ContentStr { ContentStr():ptr(NULL), contSize(0), structSize(0), X(0), Y(0){} const BYTE* ptr; int contSize; int structSize; //output std::vector m_v_Data; int X; int Y; private: ContentStr ( const ContentStr & rhs ); ContentStr & operator= ( const ContentStr & rhs ); }; The COM component invokes a DllExport method in the DLL which accepts the structure as reference and fills its value. It was working fine in VS2008. Recently I ported my code base to VS2013. Now the method throws exception when invoked. When I checked the size of the structure using sizeof operator, I was surprised a bit. VS 2008: /*Inside COM*/ sizeof(ContentStr) = 40 /*Inside DLL*/ sizeof(ContentStr) = 40 VS 2013: /*Inside COM*/ sizeof(ContentStr) = 36 /*Inside DLL*/ sizeof(ContentStr) = 32 I could see that the difference in size is due to the difference in vector size. Searching the internet gave me huge confusion hence I am posting this question on the expert forum. Could someone please explain me why is this difference seen in the sizes and help me find a solution.

        Kings

        V Offline
        V Offline
        Vi2
        wrote on last edited by
        #3

        It's very bad idea to use the complex types from one DLL to another. Firstly your DLLs can use different "packing size". Secondly these STL types can use own allocators which can be different. Thirdly these STL types can be incompatible due to different realizations of STL.

        With best wishes, Vita

        J 1 Reply Last reply
        0
        • J Jacobkingsly

          I have the following structure defined inside my DLL and a COM component we developed. struct ContentStr { ContentStr():ptr(NULL), contSize(0), structSize(0), X(0), Y(0){} const BYTE* ptr; int contSize; int structSize; //output std::vector m_v_Data; int X; int Y; private: ContentStr ( const ContentStr & rhs ); ContentStr & operator= ( const ContentStr & rhs ); }; The COM component invokes a DllExport method in the DLL which accepts the structure as reference and fills its value. It was working fine in VS2008. Recently I ported my code base to VS2013. Now the method throws exception when invoked. When I checked the size of the structure using sizeof operator, I was surprised a bit. VS 2008: /*Inside COM*/ sizeof(ContentStr) = 40 /*Inside DLL*/ sizeof(ContentStr) = 40 VS 2013: /*Inside COM*/ sizeof(ContentStr) = 36 /*Inside DLL*/ sizeof(ContentStr) = 32 I could see that the difference in size is due to the difference in vector size. Searching the internet gave me huge confusion hence I am posting this question on the expert forum. Could someone please explain me why is this difference seen in the sizes and help me find a solution.

          Kings

          S Offline
          S Offline
          Shao Voon Wong
          wrote on last edited by
          #4

          Check if the VS2008 project is 64bit while the VS2013 one is 32bit.

          J 1 Reply Last reply
          0
          • L Lost User

            I don't see how std::vector m_v_Data; will compile; vector is a template class and needs a type to define it. [edit] In VS2010 I get 20 for the size of a vector<int>, and in VS2013 I get 16. There must be some other difference in your DLL code that reduces the total by another 4 bytes. [/edit]

            J Offline
            J Offline
            Jacobkingsly
            wrote on last edited by
            #5

            it is vector of BYTE, sorry the code got modified when entered in the editor

            Kings

            L 1 Reply Last reply
            0
            • S Shao Voon Wong

              Check if the VS2008 project is 64bit while the VS2013 one is 32bit.

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

              No, both the DLL and COM are compiled in VS2013 and are compiled as 32 bit binaries.

              Kings

              1 Reply Last reply
              0
              • V Vi2

                It's very bad idea to use the complex types from one DLL to another. Firstly your DLLs can use different "packing size". Secondly these STL types can use own allocators which can be different. Thirdly these STL types can be incompatible due to different realizations of STL.

                With best wishes, Vita

                J Offline
                J Offline
                Jacobkingsly
                wrote on last edited by
                #7

                Could you please suggest me how can I make the packing size as same between COM and the DLL?

                Kings

                1 Reply Last reply
                0
                • J Jacobkingsly

                  it is vector of BYTE, sorry the code got modified when entered in the editor

                  Kings

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  My apologies also, I think your code got mangled by the HTML tags, you need to use <pre> tags around it (use the code button above the edit window) so it shows up, like:

                  //output
                  std::vector m_v_Data;
                  int X;
                  int Y;

                  There is obviously some difference between your application and your DLL. Are they both compiled with the exact same definition for your structure, i.e. using a common header file?

                  J 1 Reply Last reply
                  0
                  • L Lost User

                    My apologies also, I think your code got mangled by the HTML tags, you need to use <pre> tags around it (use the code button above the edit window) so it shows up, like:

                    //output
                    std::vector m_v_Data;
                    int X;
                    int Y;

                    There is obviously some difference between your application and your DLL. Are they both compiled with the exact same definition for your structure, i.e. using a common header file?

                    J Offline
                    J Offline
                    Jacobkingsly
                    wrote on last edited by
                    #9

                    No they are not, the DLL contains a Util method which is exposed using DLLExport and the COM loads the DLL and creates a method pointer out of it and asks it to fill the data.

                    Kings

                    L 1 Reply Last reply
                    0
                    • J Jacobkingsly

                      No they are not, the DLL contains a Util method which is exposed using DLLExport and the COM loads the DLL and creates a method pointer out of it and asks it to fill the data.

                      Kings

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Well you need to show us the exact code in the application and the DLL, so we can try to figure out what the difference may be.

                      J 1 Reply Last reply
                      0
                      • L Lost User

                        Well you need to show us the exact code in the application and the DLL, so we can try to figure out what the difference may be.

                        J Offline
                        J Offline
                        Jacobkingsly
                        wrote on last edited by
                        #11

                        I am afraid that could not be done, however if you could point me to the direction where I can start digging through or help me with how you wud have approached this issue it wud be helpful.

                        Kings

                        L 1 Reply Last reply
                        0
                        • J Jacobkingsly

                          I am afraid that could not be done, however if you could point me to the direction where I can start digging through or help me with how you wud have approached this issue it wud be helpful.

                          Kings

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Sorry, but without seeing your code I have no idea what to suggest, other than some careful reviewing of your code, and use of your debugger.

                          1 Reply Last reply
                          0
                          • J Jacobkingsly

                            I have the following structure defined inside my DLL and a COM component we developed. struct ContentStr { ContentStr():ptr(NULL), contSize(0), structSize(0), X(0), Y(0){} const BYTE* ptr; int contSize; int structSize; //output std::vector m_v_Data; int X; int Y; private: ContentStr ( const ContentStr & rhs ); ContentStr & operator= ( const ContentStr & rhs ); }; The COM component invokes a DllExport method in the DLL which accepts the structure as reference and fills its value. It was working fine in VS2008. Recently I ported my code base to VS2013. Now the method throws exception when invoked. When I checked the size of the structure using sizeof operator, I was surprised a bit. VS 2008: /*Inside COM*/ sizeof(ContentStr) = 40 /*Inside DLL*/ sizeof(ContentStr) = 40 VS 2013: /*Inside COM*/ sizeof(ContentStr) = 36 /*Inside DLL*/ sizeof(ContentStr) = 32 I could see that the difference in size is due to the difference in vector size. Searching the internet gave me huge confusion hence I am posting this question on the expert forum. Could someone please explain me why is this difference seen in the sizes and help me find a solution.

                            Kings

                            J Offline
                            J Offline
                            Jacobkingsly
                            wrote on last edited by
                            #13

                            _SECURE_SCL was enabled in COM amounting to 4 byte increase in size. Removing that solved the issue.

                            Kings

                            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