Thread: Library

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    197

    Library

    Hi...
    I have a scenario in which i would put all my implementation functions as library.Say for eg : I have a list library

    I have a function called Intialise() which returns a handle to the caller.

    And i pass this handle to all the other functions needed.

    The user may also create another list which returns a new handle and manipulate with it.

    What should i do to have the old list as well as new lists and how does the user switch between the lists.


    say for eg:
    print all the values in the newly created list


    print all the values in the list that was first created.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    If I understand your question correctly, the user just keeps the two different handles, and depending on which one they want to work with, they pass the appropriate handle to the function. This of course requires that your library keeps track of multiple handles and the lists they correspond to. An alternative is to have Initialize() create the list and return a pointer to it, and have them pass that pointer in any time they want you to work with it. That eliminates the need for you to track handles and instances.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > What should i do to have the old list as well as new lists and how does the user switch between the lists.
    The handle you pass back is really an opaque pointer to some data structure you allocate an manage.

    Within that, you have ALL the information to manage a list.

    So no matter how many handles you return to the caller, you always know which list they're talking about from the handle they pass back to you in the rest of the API.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 09:06 AM
  2. C problem - Create a Personal Library
    By Harliqueen in forum C Programming
    Replies: 33
    Last Post: 04-20-2010, 11:27 PM
  3. how to create an Import Library in Vs2008
    By khumayun in forum C++ Programming
    Replies: 2
    Last Post: 03-19-2010, 10:49 AM
  4. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  5. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM