1. We are not accepting any new account registrations at this time - watch out for announcements on Discord.

c++ export array of struct

Discussion in 'HelpDesk' started by PseudoCoder, Oct 11, 2018.

Tags:
  1. Ps

    PseudoCoder DEV Guild Member DEV Guild

    Joined:
    Sep 5, 2008
    Messages:
    141
    Likes Received:
    1,974
    Hello i'v the following function that exports a single instance of a struct :
    Code:
    struct UserIdentity
    {
    std::string name;
    int id;
    };
    
    std::map<std::string, int> g_UserIdentities = { { "Bob", 100 }, { "Jone", 101 },
                { "Alice", 102 }, { "Doe", 103 } };
             
    /*
    * Will be used in a DLL that will export UserIdentity struct
    * OUT _UserIdentity
    */
    
    void Ui_export(UserIdentity *_UserIdentity)
    {
    for (auto& t : g_UserIdentities)
        {
         _UserIdentity->name = t.first;
         _UserIdentity->id   = t.second;
        }
         
    } 
    So please how could i export an array of _UserIdentity instead of a single instance in my function
    Code:
    void Ui_export(UserIdentity *_UserIdentity)
    thank you .
     
    Last edited: Oct 11, 2018
  2. Ps

    PseudoCoder DEV Guild Member DEV Guild

    Joined:
    Sep 5, 2008
    Messages:
    141
    Likes Received:
    1,974
    Thank you all , GOT IT .
     
  3. Be

    BeErikk Registered User

    Joined:
    Oct 7, 2017
    Messages:
    6
    Likes Received:
    40
    Hm...did you find an answer by yourself or got a PM? o_Oo_O

    Anyway, you can indeed export data from a DLL. There is info on MSDN how to do it with variants and you should, of course, make a test project to find out what suits your needs best. However, personally, I wouldn't implement such a solution. DLLs are best used with a C function export interface (even if your DLL implementation is in C++). Data should be handled in the application. There are differences between UNIX shared libraries and Windows DLLs in this respect.