How to determine if DLL is COM or .NET?

被刻印的时光 ゝ 提交于 2020-01-24 03:03:46

问题


I have an updater program, the pulled files from server has mixed vb6 dll and .net DLLs in one directory.

How to determine if a dll is a COM one? (so i can invoke regsvr32 to it from the updater program)


回答1:


I guess one way to do it would be to try load the file with System.Reflection.Assembly.LoadFile(). If you get a BadImageFormatException, it's not a valid .NET assembly. There's probably a neater way of doing this, but this should work.

http://msdn.microsoft.com/en-us/library/b61s44e8.aspx




回答2:


To do this formally you could inspect the PE to find out more about what type of stuff each dll is exporting. There is a pretty interesting article on MSDN which talks about the structure. If you understand the setup, you can identify links to .Net (and thereby the lack indicating a pure COM dll).




回答3:


Why not just call regsvr on all of them. If they register then ok, if not no big deal.

It is probably best though to write an installer that has the knowledge of which ones are which and does the right thing for each.

EDIT

If you are worried about "emitting errors", don't fret.

See this usage

You can suppress messages. (/s)



来源:https://stackoverflow.com/questions/3011378/how-to-determine-if-dll-is-com-or-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!