[comp.windows.ms] Locking data in DLL's

bturner@hpcvlx.HP.COM (Bill Turner) (05/31/89)

In a note about using spawn, the question was asked about locking the DS
for a library.  This raised an interesting problem that many people overlook
when building DLL's, and that is when is the library's DS locked?

For a program, when Windows transfers control to your code it automagically
locks DS for you, and unlocks it when task switching out.  But for a library
this automatic locking/unlocking isn't done.

If you've called LocalInit, part of what it does is set the automatic lock
for the DS specified.  That means that, unless you've taken steps to unlock
DS, it will be locked regardless of what you specify in the .DEF file.

Well, knowing this you then call UnlockData after you call LocalInit.  Fine,
but now the segment is always moveable, and you will have to explicitly call
LockData and UnlockData for every procedure call.  A pain, but the only way
you can have a movable DS that works safely in a DLL.

--Bill Turner (bturner@hp-pcd.hp.com)
HP Corvallis Information Systems