Embedding resources from win32 dll to .net
I work with class treeView. i want to create the tree of files with icons. i want to extract some icons from shell32.dll. Can icon o开发者_JAVA技巧r image class work with res-protocol. how to know full path to file on res protocol?
Microsoft sternly and repeatedly has warned against this practice. The resources in shell32.dll are a private implementation detail and can change without notice. Assuming you want to ignore this: you can lift the icons out of it by P/Invoking LoadLibrary() to get a module handle and LoadImage() to get the icon. Unfortunately, the Icon constructor that takes a handle is private, you'll have to use Reflection to invoke it. Visit pinvoke.net for the declarations.
While this all works, this isn't great code that you'll enjoy maintaining. Fwiw, lifting the icons out of shell32.dll and putting it in a managed resource is very simple. In Visual Studio, use File + Open + File and open shell32.dll. You'll get a list of all the resources, navigate into the Icons node. Double click one to see what it contains, right click + Export to save it to a file. No idea how legal this is, the icons themselves don't carry a copyright notice but shell32.dll certainly does. It probably isn't.
I think you have to extract the icons from shell32 if you want to use them.
With IcoFx (freeware) you can extract icons from exe's and dll's.
精彩评论