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. Exporting a struct from a DLL

Exporting a struct from a DLL

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 3 Posters 4 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.
  • M Offline
    M Offline
    masnu
    wrote on last edited by
    #1

    Hi guys, Is it possible to export a structure from a dll without including the header file where the structure is define? For example:

    /*-------------------------
    mydllheader.h
    ------------------------------*/

    extern "C" __declspec(dllexport) struct MyStruct
    {

     MyStruct()
     {
         a = 0;
         b = 0;
     }
    
     int a;
     int b;
    

    }

    Instead of including mydllheader.h I want to do the following:

    /*-------------------------
    myimportheader.h
    ------------------------------*/

    extern "C" __declspec(dllimport) struct MyStruct

    I would like to use myimportheader.h in my projects that use the dll that way I can hide my structure implementation from the user. Is that possible? Thanks.

    L A 2 Replies Last reply
    0
    • M masnu

      Hi guys, Is it possible to export a structure from a dll without including the header file where the structure is define? For example:

      /*-------------------------
      mydllheader.h
      ------------------------------*/

      extern "C" __declspec(dllexport) struct MyStruct
      {

       MyStruct()
       {
           a = 0;
           b = 0;
       }
      
       int a;
       int b;
      

      }

      Instead of including mydllheader.h I want to do the following:

      /*-------------------------
      myimportheader.h
      ------------------------------*/

      extern "C" __declspec(dllimport) struct MyStruct

      I would like to use myimportheader.h in my projects that use the dll that way I can hide my structure implementation from the user. Is that possible? Thanks.

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

      You could do it this way but what is the point? If you hide everything from the user then what purpose is served by the structure? A better solution is to create a class that has methods but hides all variables and implementation details.

      txtspeak is the realm of 9 year old children, not developers. Christian Graus

      1 Reply Last reply
      0
      • M masnu

        Hi guys, Is it possible to export a structure from a dll without including the header file where the structure is define? For example:

        /*-------------------------
        mydllheader.h
        ------------------------------*/

        extern "C" __declspec(dllexport) struct MyStruct
        {

         MyStruct()
         {
             a = 0;
             b = 0;
         }
        
         int a;
         int b;
        

        }

        Instead of including mydllheader.h I want to do the following:

        /*-------------------------
        myimportheader.h
        ------------------------------*/

        extern "C" __declspec(dllimport) struct MyStruct

        I would like to use myimportheader.h in my projects that use the dll that way I can hide my structure implementation from the user. Is that possible? Thanks.

        A Offline
        A Offline
        Avi Berger
        wrote on last edited by
        #3

        Not if the user of your dll creates instances of MyStruct itself. It needs to be a complete type if the user of your DLL is to create instances of it. If you delegate all creation/destruction of MyStruct instances to the dll, you can achieve something like this. I've seen this sort of thing done with void *'s for the interface. I don't know if you could do this with a pointer to an incomplete type. If not, you could get a sort of type safety by wrapping the void * in a struct of its own with the definition of that struct exposed to the consuming application.

        Please do not read this signature.

        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