By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Static strings not initialized in Managed C++

P: n/a
MTL
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.

Mar 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
MTL wrote:
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.


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

-cd
Mar 17 '06 #2

P: n/a
MTL
Thanks alot, that did the trickl

Mar 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.