How to release inprocess COM Server object from Excel VBA

前端 未结 2 1145
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 19:10

How do you force Excel (2007) VBA to release references to a COM server object?

I have written an inprocess (Single instance DLL) COM Server in Visual Foxpro 9 SP2 w

2条回答
  •  伪装坚强ぢ
    2021-01-18 20:07

    Adding a shorter answer ....

    Releasing the DLL is knotty problem and one familiar to developers of in process COM components for use in Excel.

    There are two conditions that need to be satisfied

    1) Do not use an early binding library references (Tools->Reference) , use late binding instead. Early binding tools reference will hold a lock.

    2) Call CoFreeUnusedLibraries to unload COM servers which no longer have clients.

    From your sample code you are already late binding but please check your references. Whilst point 2) is referred to in payyhoyts answer no code is given.

    Here is a copy and pasteable declaration

    Private Declare Sub CoFreeUnusedLibraries Lib "ole32.dll" ()
    

提交回复
热议问题