473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Static strings not initialized in Managed C++

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
2 1310
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
MTL
Thanks alot, that did the trickl

Mar 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: trying_to_learn | last post by:
I'm learning consts in C++ and the book says that u have to initialize non-static consts inside the constructor initializer list, however "const string* stack" isn't initialized in the constructor...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
2
by: rmathieu | last post by:
Hi, I want to initialize a static String array in MC++. What I want to do is to initialize my String array like the C# way: new String {"11", "22"} but I could not find an equivalent in MC++. The...
7
by: Adam | last post by:
I have a managed cpp wrapper. Im using this in a native dll as a static variable. I need to free this library when the dll is done being used. The perfect place to do this is DllMain for...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
3
by: noleander | last post by:
Im getting a runtime error because Ive got a static object that is not properly initialized. ---------- header file xxx.hpp --------------- class SomeClass { SomeClass() { .. constructor here...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
4
by: DaTurk | last post by:
Hi, I've noticed that when trying to create a managed, auto_gcrooted variable in a antive class, the compiler throws linker exceptions. While searching some forums I found out that this is a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.