Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Warnings in c++/cli that make me a lot of headache

Warnings in c++/cli that make me a lot of headache

Scheduled Pinned Locked Moved Managed C++/CLI
c++tutorial
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hansipet
    wrote on last edited by
    #1

    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++ file std::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

    G 1 Reply Last reply
    0
    • H hansipet

      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++ file std::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

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • G George L Jackson

        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

        H Offline
        H Offline
        hansipet
        wrote on last edited by
        #3

        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

        G 2 Replies Last reply
        0
        • H hansipet

          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

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          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

          H 1 Reply Last reply
          0
          • H hansipet

            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

            G Offline
            G Offline
            George L Jackson
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • G George L Jackson

              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

              H Offline
              H Offline
              hansipet
              wrote on last edited by
              #6

              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 is std::wstring Test::teststr = L""; Isn't it? What do you do in that case? Best regards Hansjörg

              G 1 Reply Last reply
              0
              • H hansipet

                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 is std::wstring Test::teststr = L""; Isn't it? What do you do in that case? Best regards Hansjörg

                G Offline
                G Offline
                George L Jackson
                wrote on last edited by
                #7

                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

                H 1 Reply Last reply
                0
                • G George L Jackson

                  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

                  H Offline
                  H Offline
                  hansipet
                  wrote on last edited by
                  #8

                  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

                  G 1 Reply Last reply
                  0
                  • H hansipet

                    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

                    G Offline
                    G Offline
                    George L Jackson
                    wrote on last edited by
                    #9

                    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

                    H 1 Reply Last reply
                    0
                    • G George L Jackson

                      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

                      H Offline
                      H Offline
                      hansipet
                      wrote on last edited by
                      #10

                      Thank you very much!!!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups