<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
开发 Excel 插件( Addin )的时候调用了一个 COM 组件(其载体为 dll )。其实调试很简单,只要将该 dll 文件对应的 Debug 版本及 pdb 调试文件 (注意 dll 和 pdb 的文件名必须相同)。然后选择菜单 Debug->Attach to Process… ,在弹出的对话框中选择 Excel 进程即可。或者在 VS IDE 中选中,右键单击工程,选择 Properties ,然后在弹出的 Properties Dialog 的左边树上选择 Configuration Properties->Debuggin, 然后再右边的面板 Command 属性中设置 Excel.exe 对应的路径。接下来可以直接从 VS IDE 中启动调试。
看起来简单的过程可能会遇到一些奇怪的问题。开始 VS IDE 中的断点都没有办法进入,显示“ The breakpoint will not currently be hit. ”这个显然是 debug 版本的 dll 没有起作用。然后尝试直接运行 Excel 插件,发现不能正常运行。但是换成原来 release 版本的 dll 运行正常。再换成 debug 版本发现 Excel 报错:“ automation error , the specified module could not be found ”。但是实际上 dll 分明在 Excel Refrence 中所指定的路径当中。网上说可能是没有注册 dll 。其实 COM 组件早就已经注册了,现在只是替换了一个。不过还是尝试了用 regsvr32 进行注册。
regsvr32 addin.dll
结果注册过程报错:“ LoadLibrary failed - The specified module could not be found ”。然后又 google 了一下,找到一篇很有用的文章: MS-Windows Troubleshooting: regsvr32 fails with "LoadLibrary failed - The specified module could not be found" 。结果发现果然是 com 组件所依赖的其它文件找不到: debug 版本的 dll 以来的其它 dll 也全部是 debug 版本的,但是插件所在的文件夹下全是 release 版本的,而恰好开发过程中所有 debug 版本与 release 版本名字都不一样,所以就找不到文件了。利用工具 System Internals 最终确定了哪些依赖文件,然后将相应 debug 版本的 dll 全部放在插件所在目录,这下一切就正常了。
想了想还是把引用的文章贴一下(以下内容转载):
regsvr32 fails with "LoadLibrary failed - The specified module could not be found"
Symptom:
When attempting to register a COM object (e.g. Active-X component or OCX) with ‘Regsvr32
’, i.e.:
regsvr32 COM
it fails with a message box displaying:
LoadLibrary("COM") failed - The specified module could not be found
Where ‘COM
’ is the name of the COM object file.
Possible causes and remedies:
- The name of the COM object is wrong.
Check that the name supplied to regsvr32 is correct. Check both the name and that the file is in the current directory.
- The COM object requires another library which is missing.
The name of the COM object is correct, but the COM object in turn requires another DLL and it is that subsequent DLL which is missing.
There are a number of ways of identifying which DLL is missing. The following always for me:
- Download a utility called "FileMon" from System Internals . This is a free utility that lets you log all file system accesses.
- Run FileMon, it will capture all file system activity.
- Do regedt32 again. It will fail, but it is the log from FileMon which is of interest.
- Tell FileMon to stop logging, do this by clicking on the magnifying glass in the toolbar. Do not wipe the log!
- Work from the bottom of the log upwards. What you are logging for is a line that has the process as "regsvr32.exe" and the result as "FILE NOT FOUND". Under Path it will show you what DLL it was looking for. This is the missing DLL.
Once you have identified the missing DLL it is up to you how you obtain a replacement. If you are porting objects from one PC to another (which is when I've encountered this problem) then it is reasonable to assume that the "old" pc has a copy of the missing DLL.