Warnings in c++/cli that make me a lot of headache
-
Hello, I have a few warnings in c++/ cli that I don't know how to resolve: 1) Warning 1 warning C4835: 'startupDirectory' : the initializer for exported data will not be run until managed code is first executed in the host assembly FileUtils.cpp 76 okay in this there is a unmanaged class (#pragma managed(push,off)) with a static variable
class CFileUtils{ std::wstring startupDirectory(L""); }
and in the c++ filestd::wstring CFileUtils::startupDirectory(L"");
2) Warning 6 warning C4965: implicit box of integer 0; use nullptr or explicit cast AlarmViewerControl.h 594 in this case I have the following code. I have tested already all casts that I know...DataRow ^dr = dt->NewRow(); dr["clmId"] = 0;
Best regards and thanks for any hint! Hansjörg -
Hello, I have a few warnings in c++/ cli that I don't know how to resolve: 1) Warning 1 warning C4835: 'startupDirectory' : the initializer for exported data will not be run until managed code is first executed in the host assembly FileUtils.cpp 76 okay in this there is a unmanaged class (#pragma managed(push,off)) with a static variable
class CFileUtils{ std::wstring startupDirectory(L""); }
and in the c++ filestd::wstring CFileUtils::startupDirectory(L"");
2) Warning 6 warning C4965: implicit box of integer 0; use nullptr or explicit cast AlarmViewerControl.h 594 in this case I have the following code. I have tested already all casts that I know...DataRow ^dr = dt->NewRow(); dr["clmId"] = 0;
Best regards and thanks for any hint! HansjörgFirst issue: If native code executes before managed code, your application may have problems with loader lock: http://msdn2.microsoft.com/en-us/library/ms172219(vs.80).aspx[^] Second Issue: If the dr["clmId"] is an object, for example a
String^
, the compiler believes you are trying to set the object to NULL with zero which is not permitted."We make a living by what we get, we make a life by what we give." --Winston Churchill
-
First issue: If native code executes before managed code, your application may have problems with loader lock: http://msdn2.microsoft.com/en-us/library/ms172219(vs.80).aspx[^] Second Issue: If the dr["clmId"] is an object, for example a
String^
, the compiler believes you are trying to set the object to NULL with zero which is not permitted."We make a living by what we get, we make a life by what we give." --Winston Churchill
Okay I understand the problems, but what I can do? How I can have the warnings away (not only with pragma)? 1) I need unmanaged classes and there I have static instances... 2) I understand also this, but in this case the column is a integer...What I have to do? Best regards Hansjörg
-
Okay I understand the problems, but what I can do? How I can have the warnings away (not only with pragma)? 1) I need unmanaged classes and there I have static instances... 2) I understand also this, but in this case the column is a integer...What I have to do? Best regards Hansjörg
I am only seeing small snippets of your code and don't know anything about your programming requirements. So, I can only give you general advice about what I think may be wrong.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
Okay I understand the problems, but what I can do? How I can have the warnings away (not only with pragma)? 1) I need unmanaged classes and there I have static instances... 2) I understand also this, but in this case the column is a integer...What I have to do? Best regards Hansjörg
Issue #2: Have you tried manually boxing the zero?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I am only seeing small snippets of your code and don't know anything about your programming requirements. So, I can only give you general advice about what I think may be wrong.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
Hello, advice 2 was really good. It works! The only thing that I don't have tested :-( for the first point: I have a mixed c++/cli (for speed reasons) program. And for that I have in a few assemblies classes which are totally unmanaged:
#pragma managed(push,off) class Test { static std::wstring teststr; //some other functions... }
In this class I don't have the possibility to use a managed string class. And the only way (that I know) to initialize the static member isstd::wstring Test::teststr = L"";
Isn't it? What do you do in that case? Best regards Hansjörg -
Hello, advice 2 was really good. It works! The only thing that I don't have tested :-( for the first point: I have a mixed c++/cli (for speed reasons) program. And for that I have in a few assemblies classes which are totally unmanaged:
#pragma managed(push,off) class Test { static std::wstring teststr; //some other functions... }
In this class I don't have the possibility to use a managed string class. And the only way (that I know) to initialize the static member isstd::wstring Test::teststr = L"";
Isn't it? What do you do in that case? Best regards HansjörgI will try to answer your question later on after work. However, why are you writing native code in assemblies compiled by /clr? I know you said for speed reasons. However, are you aware of managed to unmanaged and unmaanaged to managed transitions (thunks) which act like speed bumps in your application. Nevertheless, if it is the only way to write the program, I understand.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I will try to answer your question later on after work. However, why are you writing native code in assemblies compiled by /clr? I know you said for speed reasons. However, are you aware of managed to unmanaged and unmaanaged to managed transitions (thunks) which act like speed bumps in your application. Nevertheless, if it is the only way to write the program, I understand.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
Thank you very much! Yes I know about the speed bumps but I'm careful with every transition (mostly from windows forms to unmanaged code)... Best regards Hansjörg
The only way I could get native
static
objects to work in managed code was to place them inside of static functions or static methods. For example:#pragma managed(push, off)
using std::wstring;
class Foo
{
public:
static const wchar_t* State(const wchar_t* value = 0)
{
static std::wstring state= L"";
if (value != 0)
state = value;
return state.c_str();
}
};
#pragma managed(pop)
using namespace System;
int main(array<System::String ^> ^args)
{
String^ str1 = gcnew String(Foo::State());
Foo::State(L"Hello!");
String^ str2 = gcnew String(Foo::State());
Console::WriteLine(str1);
Console::WriteLine(str2);
return 0;
}"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
The only way I could get native
static
objects to work in managed code was to place them inside of static functions or static methods. For example:#pragma managed(push, off)
using std::wstring;
class Foo
{
public:
static const wchar_t* State(const wchar_t* value = 0)
{
static std::wstring state= L"";
if (value != 0)
state = value;
return state.c_str();
}
};
#pragma managed(pop)
using namespace System;
int main(array<System::String ^> ^args)
{
String^ str1 = gcnew String(Foo::State());
Foo::State(L"Hello!");
String^ str2 = gcnew String(Foo::State());
Console::WriteLine(str1);
Console::WriteLine(str2);
return 0;
}"We make a living by what we get, we make a life by what we give." --Winston Churchill