How to load resource strings?

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

I am writing my first managed project and I am a bit confused in loading
resource strings. In old unmanaged C++ if I had a resource string in my
rc file called GX_ERR_DEVICE_ALREADY_OPEN. I would simply call:

int LoadString(HINSTANCE hInstance,
UINT uID,
LPTSTR lpBuffer,
int nBufferMax
);


inserting GX_ERR_DEVICE_ALREADY_OPEN for uID.


I understand that I now use to ResourceManager?

I tried:


String *GetErrMsg ()
{

ResourceManager *rm = new
ResourceManager("app",this->GetType()->Assembly);
return rm->GetString("GX_ERR_DEVICE_ALREADY_OPEN");
}

where app is the name of my rc file. But this does not seem to work.
Actually it doesn't make sense to me that I would pass a String in
GetString so I must be doing something wrong.

Where did I go wrong?
 
M

Marcus Heege

You have to use "YourProjectName.app" instead of "app" for the first
argument.

If you look at the project properties of app.resx in your project, you will
see that the default setting for the resource file name is
$(IntDir)\$(RootNamespace).$(InputName).resources.

Marcus Heege
 
B

Bruce

Marcus said:
You have to use "YourProjectName.app" instead of "app" for the first
argument.

If you look at the project properties of app.resx in your project, you will
see that the default setting for the resource file name is
$(IntDir)\$(RootNamespace).$(InputName).resources.

Marcus Heege

Thanks!

I don't have an app.resx. How is one created? I do have a resx file
for each one of the classes in my project. How do I create an app.resx?

Bruce
 
B

Bruce

Marcus said:
You have to use "YourProjectName.app" instead of "app" for the first
argument.

If you look at the project properties of app.resx in your project, you will
see that the default setting for the resource file name is
$(IntDir)\$(RootNamespace).$(InputName).resources.

Marcus Heege


And how do I read strings out of my .rc file? Can I no longer do that?

I created a generic class. It has no resx file. Can one be created
for it? If so how? I don't see any way to create one.
 
M

Marcus Heege

Bruce said:
Thanks!

I don't have an app.resx. How is one created? I do have a resx file for
each one of the classes in my project. How do I create an app.resx?

Bruce

To create this file, choose the project's context menu, then Add Item, them
Assembly Resurce (resx).

Marcus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top