Resources and Managed C++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have recently been trying to add some bitmaps to my Managed C++ app as
resources. However, I have found that the availible documentation on this
only covers C# and that the C++ IDE does not support this funtionality. I
hardly know C# (except for its similarities with C++), and would prefer not
to have to keep a C# library of resources. Is there any way to embed
resources as you can in C#?
I will appreciate your assistance.
Reuben.
 
Reuben,
I have recently been trying to add some bitmaps to my Managed C++ app as
resources. However, I have found that the availible documentation on this
only covers C# and that the C++ IDE does not support this funtionality. I
hardly know C# (except for its similarities with C++), and would prefer not
to have to keep a C# library of resources. Is there any way to embed
resources as you can in C#?
I will appreciate your assistance.

The linker fully supports this, via the /assemblyresource switch. Just
create your .resources files (or whatever you need), and add the necessary
options to the linker command line to link them in as resources. Not as
automatic as with C#, but perfectly possible, still.
 
How do I add the switch to the linker's command line while still using VS
..NET to build my solution?
 
Reuben,
How do I add the switch to the linker's command line while still using VS
.NET to build my solution?

Just use the project's property page, under the linker options.
 
Thanks for your help. I don't suppose you could tell me how I could enumerate
and load the resouces?
 
Reuben,
Thanks for your help. I don't suppose you could tell me how I could
enumerate
and load the resouces?

You can use the ResourceReader and ResourceManager classes in the
System.Resources namespace for that.
 
I have tried using those classes but failed. I can successfully create a
ResourceManager but not a ResourceReader and am unable to use the GetObject
method; the second and third lines given result in exceptions which are
caused apparently because I am using the wrong filenames. I have also tried
suffixing '.resources.' to the filenames in those lines to no avail. The
resource I have embedded is a single bitmap called 'Hello.bmp'. Your
assistance is appreciated.
Reuben

ResourceManager* rm = new ResourceManager(S"Hello.bmp",
this->GetType()->Assembly);
ResourceReader* rr = new ResourceReader(S"Hello.bmp");
rm->GetObject(S"Hello.bmp");
 
Reuben,
I have tried using those classes but failed. I can successfully create a
ResourceManager but not a ResourceReader and am unable to use the
GetObject
method; the second and third lines given result in exceptions which are
caused apparently because I am using the wrong filenames. I have also
tried
suffixing '.resources.' to the filenames in those lines to no avail. The
resource I have embedded is a single bitmap called 'Hello.bmp'. Your
assistance is appreciated.
Reuben

ResourceManager* rm = new ResourceManager(S"Hello.bmp",
this->GetType()->Assembly);
ResourceReader* rr = new ResourceReader(S"Hello.bmp");
rm->GetObject(S"Hello.bmp");

Did you create a .resource file first, or are you specifying Hello.bmp
directly in the /assemblyresource switch?

Here's an example I posted a while ago that used ResourceManager and a
..resources file:

http://groups-beta.google.com/group/microsoft.public.dotnet.languages.vc/msg/0724e61040bf4ed9
 
I directly embedded the bitmap using the switch, since there wasn't a
'resouce file' option in the 'add new file' dialog box. But I didn't
understand what that code had to do wth resources, other than the line where
it used the ResourceManager to obtain that string. Thanks for your help.
 
Back
Top