Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Embedded Resources in C++/CLI

Embedded Resources in C++/CLI

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++visual-studiohardware
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Oddball
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • O Oddball

      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.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Assembly.GetManifestResourceStream

      led mike

      O 1 Reply Last reply
      0
      • L led mike

        Assembly.GetManifestResourceStream

        led mike

        O Offline
        O Offline
        Oddball
        wrote on last edited by
        #3

        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.

        M D 2 Replies Last reply
        0
        • O Oddball

          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.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          O 1 Reply Last reply
          0
          • M Mark Salsbery

            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:

            O Offline
            O Offline
            Oddball
            wrote on last edited by
            #5

            Mark, My mistake! I gave MSDN only a cursory glance, and ended up looking at _Assembly::GetManifestResourceStream residing in System.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!

            1 Reply Last reply
            0
            • O Oddball

              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.

              D Offline
              D Offline
              d3m0n
              wrote on last edited by
              #6

              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")

              O 1 Reply Last reply
              0
              • D d3m0n

                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")

                O Offline
                O Offline
                Oddball
                wrote on last edited by
                #7

                Hey, I'm glad you were able to find the post, then! It always drives me crazy when googling around for answers leads me to a thread that ends in "Oh, I fixed it, never mind" with no solution. :-D

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups