How to release inprocess COM server from Excel VBA

How to get Excel (2007) VBA to issue links to a COM server object?

I wrote the inprocess COM server (Single instance DLL) in Visual Foxpro 9 SP2, which was created from Excel VBA code on my development machine. There seems to be a link in Excel to the / dll COM object, although I set it = Nothing. This does not allow me to rebuild the DLL due to the message "Deny access to TestCOM.dll files" until I exit Excel, which is a pain every time I want to make changes and test it.

I welded the code to a very simple test setup: The VFP9 project (TestCOM) has only one .prg file with the following contents

DEFINE CLASS TestClass As Session OLEPUBLIC

ENDDEFINE

The VBA code is as follows:

Sub Test()

    Set objTest = CreateObject("TestCOM.TestClass")
    Set objTest = Nothing

End Sub

COM- VBA, . DIMing , . VFP DLL, .

VFP/dll INPROCESS/DLL VBA, , OUTOFPROCESS/EXE VBA, .

COM-, , COM- Visual Foxpro 9 2, # OP , , , ; .

+5
2

, COM- DLL, , Excel COM, , ProgID, ClassID. inproc, , DLL LoadLibrary , factory DLL. , , Excel LoadLibrary DLL, , Excel FreeLibrary .

COM-, . CoCreateInstance() ( VBA New CreateObject, API Win32). LoadLibrary , . CoFreeUnusedLibraries(), COM-, . factory , , DLL , , COM- . Excel, , .

COM- , DLL, -. Excel DLL COM .

DLL, ( ), DllHost. OleView ProgId, (dllhost). , , . , COM , . oleautomation , .

+6

....

DLL COM Excel.

,

1) (Tools- > Reference), . .

2) CoFreeUnusedLibraries, COM, .

, , , . 2) answeryhoyts answer, .

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

All Articles