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

[1470 byte] By [besserer] at [2008-2-13]
# 1
Well, the only way I can suggest you do this is typeid(MainForm) instead of this->GetType.
crescens2k at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...