How to access custom resources?

Hi guys,

I've just started to use Visual C++ 2005 Express, and don't know how to access embedded resources.

I created CLR Empty project, added MainForm.h and MainForm.cpp files under Solution-->Project-->Header Files/Source Files, respectively. Then - an icon under Solution-->Project-->Resource files-->"icon.ico". Then I put some code:

MainForm::MainForm(void)
{
// That is my custom icon I want to use
this->Icon = gcnew System::Drawing::Icon(this->GetType(), "icon.ico");
}

It compiles and builds OK. However, when I run it form within IDE, it gives me:

An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll

Additional information: Resource 'icon.ico' cannot be found in class 'MyNamespace.MainForm'.


Apparently, something is wrong with how I reference this resource in my code, right I was not able to find any workarounds in the help supplied.

Can anyone help me with that

Thanks in advance.

besserer



Answer this question

How to access custom resources?

  • Bill Miller

    Well, the only way I can suggest you do this is typeid(MainForm) instead of this->GetType.

  • How to access custom resources?