GdiPlusX: Clear DLLs when released

Topics: General
Jan 28, 2008 at 11:51 AM
I'd like to have your opinion on the need to use "CLEAR DLL" function when an API function is released.
Should we do this with GdiPlusX ?
Developer
Jan 29, 2008 at 12:07 PM

Hi Cesar,

Is there any benefit to releasing the API function? The down side would be that it may add some overhead if we have to re-DECLARE it when it is required again.
Jan 29, 2008 at 12:15 PM
Hi Bo,

I really don't know, and that's why I asked this ;-)
I've seen some examples when people release the DLLs from the memory, and I really don't see a need for doing this... but would like to know more about this thing.

In the VFP HELP we have for CLEAR DLL:


"DLLS cAliasNameList
Clears from memory external shared libraries registered with DECLARE - DLL. cAliasNameList is a comma separated list of function aliases to remove from memory as in the following example:

CLEAR DLLS "RegCloseKey","RegOpenKey"

If you used no alias in the declaration, cAliasNameList is the same as the function name. If you specify no cAliasNameList, all DLLS are removed from memory. You can use the ADLLS( ) Function to determine which DLLs are loaded.

See DECLARE - DLL Command for more information about registering external shared library functions. "
Developer
Jan 29, 2008 at 1:45 PM
In my opinion the CLEAR DLLS has the potential for doing more harm than good. In one hand, it is a good idea to restore back the environment to whatever it was before you ran your routine. The problem with the DECLARE DLL/RELEASE DLLS calls is that you can remove a DECLARE that someone else had set up before calling your routine. All DECLARE - DLL calls are global. You can't isolate it like a Session or LOCAL.

The best you can do is give it a unique alias with the AS clause so the risk of CLEARing someone elses DECLARE goes way down. But in cases like the GDIPlusX library, you have different instances of the same class. If you did your DECLARE's in the Init( )and CLEAR DLLs in the Destroy( ), you might kill your own declaration when one object is released before the other. Then that leaves you having to either re-DECLARE on every function call or checking ADLLS on every function call. My test show this can be slow.

I think it is easier to just let them hang out in memory. Even with the GDIPlusX library with its potential of almost 600 DECLAREs, I haven't seen any memory issues. Maybe someone else who has researched this may have more info on the risk of leaving the API loaded. But from what I've seen their is no risk.
Developer
Jan 29, 2008 at 3:04 PM
An alias wouldn't help. In VFP each API function can only be declared once. If you create a second one with an alias, the second one overwrites the first declaration.
Developer
Jan 29, 2008 at 10:34 PM
Edited Jan 29, 2008 at 10:37 PM

cwollenhaupt wrote:
An alias wouldn't help. In VFP each API function can only be declared once. If you create a second one with an alias, the second one overwrites the first declaration.


That is true for VFP6. In either VFP7 or VFP8 and later you can have multiple declares of the same function with different aliases
Developer
Feb 1, 2008 at 12:30 PM
Edited Feb 1, 2008 at 12:32 PM
I also think it is not worth the trouble to issue a CLEAR DLLS on any API function declared.

>That is true for VFP6. In either VFP7 or VFP8 and later you can have multiple declares of the same function with different aliases

Just beware that if you declare an API function with an alias and latter declare the same API function without an alias, the first aliased declare will vanish. So if you dont wrap your dll declares in a VFP function and intend to use aliases, you must first declare the API function without an alias, and then with the desired alias.

This does not matter if you wrap the API declares in VFP functions like GDIPLUSX and the next version of the ctl32 classes do, like:

********************************************************************************
Function apiClientToScreen(m.nHWnd, m.lpPoint)
********************************************************************************
Declare Integer ClientToScreen In win32api As apiClientToScreen ;
Integer nHWnd, ;
String @lpPoint
Return apiClientToScreen(m.nHWnd, @m.lpPoint)
Endfunc
Developer
Feb 1, 2008 at 1:41 PM

Just beware that if you declare an API function with an alias and latter declare the same API function without an alias, the first aliased declare will vanish. So if you dont wrap your dll declares in a VFP function and intend to use aliases, you must first declare the API function without an alias, and then with the desired alias.


Arrrrrrgh, that sux. I thought this was fixed, but it looks like they just made it slightly better. Well, I like wrapping the APIs anyway, problem solved!
Developer
Feb 1, 2008 at 2:54 PM
I never noticed that the behavior changed in VFP 7. Thanks, Bo!

In any case, in my Advanced API session I suggested using your approach of having a PRG with the same name as the API function. That's a nice trick to avoid errors due to CLEAR DLLS.