Hi Mike,

I don't understand if TBDI_Close is your internal function or thinBASIC keyword.

I think for de-initialization part of thinBASIC module is dedicated function called UnLoadLocalSymbols.
It looks something like this in SDK template:
[code=thinbasic]
'----------------------------------------------------------------------------
FUNCTION UnLoadLocalSymbols ALIAS "UnLoadLocalSymbols" () EXPORT AS LONG
' This function is automatically called by thinCore whenever this DLL is unloaded.
' This function CAN be present but it is not necessary. If present, this function
' will be executed by thinBasic core when module will be released.
' Use this function to perform uninitialize process, if needed.
'----------------------------------------------------------------------------

'---
'Add here DeInitialization code if needed
'---

FUNCTION = 0&
END FUNCTION
[/code]

I don't use LibMain at all. But maybe I get your problem wrong.

Anyway, have a nice day ( and dinner ),
Petr