c++ - Close access to a dll in Excel -
i'm working on project using c++ , excel. made dll export c++ function in excel. problem when test function in excel , want modify dll, need quit excel because it's still running .dll file, , visual studio c++ can't delete previous dll make other.
it's bit annoying close , launch again excel everytime know if there way close access dll when vba script finished.
thanks!
one method use run separate excel instance , automate opening/closing excel so... (this pseudocode typed in browser)
sub testmydll() dim xl new excel.application xl.workbooks.open "file" xl.run "myfunctioncall" xl.workbooks(1).close false xl.quit set xl = nothing end sub a second method dynamically load , unload dll. method use. test copied winhttp.dll different directory , called my.dll. not put dll in same directory workbook containing code or excel load dll.
option explicit private declare function freelibrary lib "kernel32" (byval hlibmodule long) long private declare function loadlibrary lib "kernel32" alias "loadlibrarya" (byval lplibfilename string) long 'my.dll copy of winhttp.dll in directory other workbook saved. 'calling result in error unless call loadlibrary first private declare function winhttpcheckplatform lib "my.dll" () long private sub foo() dim lb long lb = loadlibrary("c:\users\david\downloads\my.dll") msgbox winhttpcheckplatform 'i found had repeated calls freelibrary force reference count 'to 0 dll unloaded. until freelibrary(lb) = 0 loop end sub
Comments
Post a Comment