I have former VC++ 6.0 application which was ported to .NET.
Now we continue to develop this app under VS.NET. The app
now contains both managed and unmanaged classes.
Now I have a problem with usage of resources in managed classes.
For example I want to display warning message and want to load
that warning message from the resource file. The problem is that
in this mixed managed/unmanaged project I don't have pure managed
resources (like for example in C#) and I can't use ResourceManager
to get strings from resources.
The project still has old unmanaged resource file (.rc)
So the only option I see is the following:
// Load from unmanaged resource file
CString strMsg ;
strMsg.LoadString(IDS_READ_PROGRAM_STATUS ) ;
// Convert to managed string
String* strMsgManaged = Marshal::PtrToStringAnsi(static_cast<IntPtr>(strMsg
) ) ;
This approach looks very ugly to me.
So here are my questions:
Is there simple way to load string from unmanaged resource file to managed
String object?
What are the best practices to handle resources in mixed managed/unmanaged
C++ projects?
Thanks
> The project still has old unmanaged resource file (.rc)
> So the only option I see is the following:
[quoted text clipped - 8 lines]
>
> This approach looks very ugly to me.
Yes.
> So here are my questions:
>
> Is there simple way to load string from unmanaged resource file to managed
> String object?
Why not just do:
String *strMsgManaged = strMsg;
?

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Steve - 23 Jun 2005 20:18 GMT
Agree,
String *strMsgManaged = strMsg;
looks much better, but the main question how to load strings from unmanaged
resource file to managed String object remained unanswered ...
> > The project still has old unmanaged resource file (.rc)
> > So the only option I see is the following:
[quoted text clipped - 21 lines]
>
> ?
Jochen Kalmbach [MVP] - 23 Jun 2005 20:32 GMT
Hi Steve!
> String *strMsgManaged = strMsg;
> looks much better, but the main question how to load strings from unmanaged
> resource file to managed String object remained unanswered ...
This is exactly what you are doing, isn´t it?
What answer do you expect?
In managed world you can use "ResourceManager" to load strings from
managed-resources (resx).
In unmanaged world you can use LoadString...
There is no world between them...

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/