Embedded Resources in C++/CLI
-
Hello, everyone. I am absolutely at my wit's end with this issue, and I really hope that one of you can give me a nudge in the right direction. I am working on a custom UserControl that I will use in several other projects. Everything is going great, except for the fact that I cannot figure out how to embed images in the compiled DLL so that they can be accessed programmatically. To simplify my question, let's say that I want to load one image from a selection of several within the executable and display it in a PictureBox, since being able to do that will enable me to do what I'm actually working on. I don't want to preload an ImageList, since my images are larger than it can handle. I've found a ton of documentation on using resource files in Visual Studio, but it all seems very geared towards localization, which makes them way more complicated than what I am trying to accomplish. I've tried adding a .resx file containing the images to my project and accessing them with a ResourceManager, but I get runtime errors to the effect that my resource file was not properly linked it, leading me to believe I'm going about the whole thing wrong. This just can't be this complicated. Can someone please give me a quick primer on how to create/interact with embedded images in C++/CLI without messing with all of that localization madness? Thank you all so very much.
-
Hello, everyone. I am absolutely at my wit's end with this issue, and I really hope that one of you can give me a nudge in the right direction. I am working on a custom UserControl that I will use in several other projects. Everything is going great, except for the fact that I cannot figure out how to embed images in the compiled DLL so that they can be accessed programmatically. To simplify my question, let's say that I want to load one image from a selection of several within the executable and display it in a PictureBox, since being able to do that will enable me to do what I'm actually working on. I don't want to preload an ImageList, since my images are larger than it can handle. I've found a ton of documentation on using resource files in Visual Studio, but it all seems very geared towards localization, which makes them way more complicated than what I am trying to accomplish. I've tried adding a .resx file containing the images to my project and accessing them with a ResourceManager, but I get runtime errors to the effect that my resource file was not properly linked it, leading me to believe I'm going about the whole thing wrong. This just can't be this complicated. Can someone please give me a quick primer on how to create/interact with embedded images in C++/CLI without messing with all of that localization madness? Thank you all so very much.
-
Hey, thanks for the reply. I finally managed to figure out my issue, but I sure do appreciate the help. For my own learning, though, MSDN says that Assembly.GetManifestResourceStream should not be called from managed code. Why did you direct me towards that method? In case anyone as confused as I was finds this with Google or something, my problem was that I wasn't supplying the ResourceManager constructor with the proper arguments. If your project namespace is "Project," and your included .resx file is named "Stuff.resx," then you need to create the ResourceManager like this:
ResourceManager^ resources = gcnew ResourceManager("Project.Stuff", Reflection::Assembly::GetExecutingAssembly());
It was the "Project.Stuff" bit that got me. I wasn't getting the point from the exception thrown when I tried to use "Stuff" Thanks again.
-
Hey, thanks for the reply. I finally managed to figure out my issue, but I sure do appreciate the help. For my own learning, though, MSDN says that Assembly.GetManifestResourceStream should not be called from managed code. Why did you direct me towards that method? In case anyone as confused as I was finds this with Google or something, my problem was that I wasn't supplying the ResourceManager constructor with the proper arguments. If your project namespace is "Project," and your included .resx file is named "Stuff.resx," then you need to create the ResourceManager like this:
ResourceManager^ resources = gcnew ResourceManager("Project.Stuff", Reflection::Assembly::GetExecutingAssembly());
It was the "Project.Stuff" bit that got me. I wasn't getting the point from the exception thrown when I tried to use "Stuff" Thanks again.
Oddball wrote:
MSDN says that Assembly.GetManifestResourceStream should not be called from managed code
Interesting, since it returns a managed object. :) Where did you see that?? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Oddball wrote:
MSDN says that Assembly.GetManifestResourceStream should not be called from managed code
Interesting, since it returns a managed object. :) Where did you see that?? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark, My mistake! I gave MSDN only a cursory glance, and ended up looking at
_Assembly::GetManifestResourceStream
residing inSystem.Runtime.InteropServices
without realizing it. That page contains the line "This method is for access to managed classes from unmanaged code, and should not be called from managed code" immediately before a link to where I should have been looking. Thanks again! -
Hey, thanks for the reply. I finally managed to figure out my issue, but I sure do appreciate the help. For my own learning, though, MSDN says that Assembly.GetManifestResourceStream should not be called from managed code. Why did you direct me towards that method? In case anyone as confused as I was finds this with Google or something, my problem was that I wasn't supplying the ResourceManager constructor with the proper arguments. If your project namespace is "Project," and your included .resx file is named "Stuff.resx," then you need to create the ResourceManager like this:
ResourceManager^ resources = gcnew ResourceManager("Project.Stuff", Reflection::Assembly::GetExecutingAssembly());
It was the "Project.Stuff" bit that got me. I wasn't getting the point from the exception thrown when I tried to use "Stuff" Thanks again.
Oddball wrote:
In case anyone as confused as I was finds this with Google or something
Got it in one! After a whole day of googling I finally entered the correct set of keywords that led me here. Your reply was absolutely perfect for what I needed. I have been going insane all day :mad: Thank you so much. :rose:
Cheers [d3m0n] Email (replace "***" with "key")
-
Oddball wrote:
In case anyone as confused as I was finds this with Google or something
Got it in one! After a whole day of googling I finally entered the correct set of keywords that led me here. Your reply was absolutely perfect for what I needed. I have been going insane all day :mad: Thank you so much. :rose:
Cheers [d3m0n] Email (replace "***" with "key")