@geennaam
Quote:
I have a library which can be opened by one program only because it gains exclusive access over hardware.
You would normally not implement this via OpenLibrary/CloseLibrary.
You would rather allow the library to be opened by everybody. The library would have a gain_access and a release_access function. The gain_access function grants exclusive access for the first caller and fails for any successive caller until the first caller calls release_access.
For those callers where gain_access fails it could have a third function to supply data to the first caller.
How you implement this internally is up to you. For example the gain_access function could spawn a background process which listens to a message port. The supply_data function would then send the data to the port.