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++ / March 2006

Tip: Looking for answers? Try searching our database.

Static strings not initialized in Managed C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MTL - 16 Mar 2006 23:07 GMT
I've created a managed wrapper class for a c++ .dll i want to call from
a c-sharp project.  It works fine except that any static strings that
are created within any of the classes of my c++ .dll aren't getting
initialized...i.e. they are always empty!  The code looks something
like this (abridged):

//WrapperClass.cpp
public __gc class WrapperClass
{
  void myMethod()
  {
     UnmanagedClass cl();
     string str = cl.getString();
  }
}

//UnmanagedClass.h
class UnmanagedClass
{
  public:
     static string str;
}

//UnmanagedClass.cpp
public class UnmanagedClass()
{
  string UnmanagedClass::str("hello world");
  string getString()
  {
     return str;
  }

}

Basically the static member "str" is always empty...i.e. it never gets
assigned the "hello world" value.  This works fine when managed
extensions aren't involved.  Does anyone know what's going on.
Carl Daniel [VC++ MVP] - 17 Mar 2006 05:10 GMT
> I've created a managed wrapper class for a c++ .dll i want to call
> from a c-sharp project.  It works fine except that any static strings
[quoted text clipped - 33 lines]
> assigned the "hello world" value.  This works fine when managed
> extensions aren't involved.  Does anyone know what's going on.

You need to call __crt_dll_initialize() yourself.  See KB article 814472 at
http://support.microsoft.com/?id=814472.

-cd
MTL - 17 Mar 2006 20:15 GMT
Thanks alot, that did the trickl

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.