Accessing objects in resource files
-
Thank you very much for your help. I have tried your code, it compiles but I get the error "Stream is not a valid resource file" I created a MyResources.RES file using RC.exe and compiled the app with the following command line : csc /debug- /t:winexe /win32res:MyResources.RES /w:4 /o+ *.cs It seems to embed the resources in the exe as it much larger than if i do not have the /win3res switch any idea why it won't work?
-
Thank you very much for your help. I have tried your code, it compiles but I get the error "Stream is not a valid resource file" I created a MyResources.RES file using RC.exe and compiled the app with the following command line : csc /debug- /t:winexe /win32res:MyResources.RES /w:4 /o+ *.cs It seems to embed the resources in the exe as it much larger than if i do not have the /win3res switch any idea why it won't work?
Assuming you're not creating the resource you're consuming (if you were, I would suggest saving a lot of hassle and just using the ResourceWriter type), and you're stuck with a Win32 resource, you should be able to use the ResourceManager type to get what you need if, as your example suggests, you're embedding the resource in your application assembly. Example (where the byte array is your serialized image stream):
public byte[] Binary(string key) { ResourceManager resManager = new ResourceManager("[ASSEMBLYNAME]", This.GetType().Assembly); return (byte[]) resManager.GetObject(key); }
Here[^] is a link with a little more info. Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
-
Assuming you're not creating the resource you're consuming (if you were, I would suggest saving a lot of hassle and just using the ResourceWriter type), and you're stuck with a Win32 resource, you should be able to use the ResourceManager type to get what you need if, as your example suggests, you're embedding the resource in your application assembly. Example (where the byte array is your serialized image stream):
public byte[] Binary(string key) { ResourceManager resManager = new ResourceManager("[ASSEMBLYNAME]", This.GetType().Assembly); return (byte[]) resManager.GetObject(key); }
Here[^] is a link with a little more info. Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
Using win32 resources looks very complicated (looked your url) Maybe I am going about it all the wrong way. What is the best way to use icons and jpgs/bmps in a c# application? Would I need to have seperate files to keep with the exe or can they be embedded into the exe? At the moment I have 6 BMPs that I use in an image list for use on a listview, and at the moment I have the exe and the 6 BMP files in the same folder so i can access them. I also would like to add an icon the exe and the status bar and stop using the default one. Would I need to have seperate file(s) to the exe to allow this? Thanks again for your help
-
Using win32 resources looks very complicated (looked your url) Maybe I am going about it all the wrong way. What is the best way to use icons and jpgs/bmps in a c# application? Would I need to have seperate files to keep with the exe or can they be embedded into the exe? At the moment I have 6 BMPs that I use in an image list for use on a listview, and at the moment I have the exe and the 6 BMP files in the same folder so i can access them. I also would like to add an icon the exe and the status bar and stop using the default one. Would I need to have seperate file(s) to the exe to allow this? Thanks again for your help
Using Win32 resources is not particularly complicated in general, but the .Net Framework does not have stellar legacy support built in. See the link in my initial post, using ResourceWriter and ResourceReader. It should do exactly what you're suggesting, and provides examples for how to read from and write to .resources files. You can put more than one resource in a .resources file; they are added in key/value pairs. Good luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
-
Using Win32 resources is not particularly complicated in general, but the .Net Framework does not have stellar legacy support built in. See the link in my initial post, using ResourceWriter and ResourceReader. It should do exactly what you're suggesting, and provides examples for how to read from and write to .resources files. You can put more than one resource in a .resources file; they are added in key/value pairs. Good luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’