Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

How to handle resources in mixed managed/unmanaged C++ projects?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 23 Jun 2005 19:55 GMT
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
Jochen Kalmbach [MVP] - 23 Jun 2005 19:59 GMT
> 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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.