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. Error with compiling code..

Error with compiling code..

Scheduled Pinned Locked Moved Managed C++/CLI
c++csharpvisual-studiohelp
11 Posts 4 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.
  • A Offline
    A Offline
    ALQallaf
    wrote on last edited by
    #1

    hello everythings gos good with the code Below, but when i try to make object (MessageQueue TheQueue = new MessageQueue;), it give me an errors says : Error 1 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 2 error C3624: 'System::ComponentModel::Component': use of this type requires a reference to assembly 'System' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 3 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 4 error C2750: 'System::Messaging::MessageQueue' : cannot use 'new' on the reference type; use 'gcnew' instead c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 5 error C3642: 'System::Messaging::MessageQueue::MessageQueue(void)' : cannot call a function with __clrcall calling convention from native code c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 6 error C3175: 'System::Messaging::MessageQueue::MessageQueue' : cannot call a method of a managed type from unmanaged function 'SendToQueue' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 7 error C2664: 'System::Messaging::MessageQueue::MessageQueue(System::String ^)' : cannot convert parameter 1 from 'System::Messaging::MessageQueue *' to 'System::String ^' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 ------------------------------------------------------ ------------------------------------------------------ #include "stdafx.h" #using <system.messaging.dll> using namespace System::Messaging; #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } int _stdcall Sum(int inA, int inB) { return (inA + inB); } int _stdca

    M M N 3 Replies Last reply
    0
    • A ALQallaf

      hello everythings gos good with the code Below, but when i try to make object (MessageQueue TheQueue = new MessageQueue;), it give me an errors says : Error 1 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 2 error C3624: 'System::ComponentModel::Component': use of this type requires a reference to assembly 'System' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 3 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 4 error C2750: 'System::Messaging::MessageQueue' : cannot use 'new' on the reference type; use 'gcnew' instead c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 5 error C3642: 'System::Messaging::MessageQueue::MessageQueue(void)' : cannot call a function with __clrcall calling convention from native code c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 6 error C3175: 'System::Messaging::MessageQueue::MessageQueue' : cannot call a method of a managed type from unmanaged function 'SendToQueue' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 7 error C2664: 'System::Messaging::MessageQueue::MessageQueue(System::String ^)' : cannot convert parameter 1 from 'System::Messaging::MessageQueue *' to 'System::String ^' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 ------------------------------------------------------ ------------------------------------------------------ #include "stdafx.h" #using <system.messaging.dll> using namespace System::Messaging; #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } int _stdcall Sum(int inA, int inB) { return (inA + inB); } int _stdca

      M Offline
      M Offline
      Milton Karimbekallil
      wrote on last edited by
      #2

      Here agin u chose an an unmanged project type insted of a managed one. Hope my reply to ur post below will make things clear. rgds...milton

      1 Reply Last reply
      0
      • A ALQallaf

        hello everythings gos good with the code Below, but when i try to make object (MessageQueue TheQueue = new MessageQueue;), it give me an errors says : Error 1 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 2 error C3624: 'System::ComponentModel::Component': use of this type requires a reference to assembly 'System' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 3 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 4 error C2750: 'System::Messaging::MessageQueue' : cannot use 'new' on the reference type; use 'gcnew' instead c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 5 error C3642: 'System::Messaging::MessageQueue::MessageQueue(void)' : cannot call a function with __clrcall calling convention from native code c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 6 error C3175: 'System::Messaging::MessageQueue::MessageQueue' : cannot call a method of a managed type from unmanaged function 'SendToQueue' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 7 error C2664: 'System::Messaging::MessageQueue::MessageQueue(System::String ^)' : cannot convert parameter 1 from 'System::Messaging::MessageQueue *' to 'System::String ^' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 ------------------------------------------------------ ------------------------------------------------------ #include "stdafx.h" #using <system.messaging.dll> using namespace System::Messaging; #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } int _stdcall Sum(int inA, int inB) { return (inA + inB); } int _stdca

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        You've told the compiler that SendToQueue() is unmanaged, yet you're trying to use managed code in it. And it should be MessageQueue^ theQueue = gcnew MessageQueue;

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        A 1 Reply Last reply
        0
        • A ALQallaf

          hello everythings gos good with the code Below, but when i try to make object (MessageQueue TheQueue = new MessageQueue;), it give me an errors says : Error 1 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 2 error C3624: 'System::ComponentModel::Component': use of this type requires a reference to assembly 'System' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 3 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 4 error C2750: 'System::Messaging::MessageQueue' : cannot use 'new' on the reference type; use 'gcnew' instead c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 5 error C3642: 'System::Messaging::MessageQueue::MessageQueue(void)' : cannot call a function with __clrcall calling convention from native code c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 6 error C3175: 'System::Messaging::MessageQueue::MessageQueue' : cannot call a method of a managed type from unmanaged function 'SendToQueue' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 Error 7 error C2664: 'System::Messaging::MessageQueue::MessageQueue(System::String ^)' : cannot convert parameter 1 from 'System::Messaging::MessageQueue *' to 'System::String ^' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26 ------------------------------------------------------ ------------------------------------------------------ #include "stdafx.h" #using <system.messaging.dll> using namespace System::Messaging; #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } int _stdcall Sum(int inA, int inB) { return (inA + inB); } int _stdca

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          ALQallaf wrote:

          MessageQueue TheQueue = new MessageQueue;

          As Mike said, you need to use gcnew and not new. Alternatively you can use stack semantics.

          MessageQueue TheQueue;
          TheQueue.Func(...);

          Regards, Nish


          Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
          The Ultimate Grid - The #1 MFC grid out there!

          A 1 Reply Last reply
          0
          • M Michael Dunn

            You've told the compiler that SendToQueue() is unmanaged, yet you're trying to use managed code in it. And it should be MessageQueue^ theQueue = gcnew MessageQueue;

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

            A Offline
            A Offline
            ALQallaf
            wrote on last edited by
            #5

            nothing changes still have errors when i place MessageQueue^ theQueue = gcnew MessageQueue; inside my function SendToQueue()

            M 1 Reply Last reply
            0
            • N Nish Nishant

              ALQallaf wrote:

              MessageQueue TheQueue = new MessageQueue;

              As Mike said, you need to use gcnew and not new. Alternatively you can use stack semantics.

              MessageQueue TheQueue;
              TheQueue.Func(...);

              Regards, Nish


              Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
              The Ultimate Grid - The #1 MFC grid out there!

              A Offline
              A Offline
              ALQallaf
              wrote on last edited by
              #6

              i tryed your syntax , but still having an errors nothing changed

              N 1 Reply Last reply
              0
              • A ALQallaf

                i tryed your syntax , but still having an errors nothing changed

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #7

                ALQallaf wrote:

                i tryed your syntax , but still having an errors nothing changed

                Check the following :

                • Are you using the old syntax? You cannot use C++/CLI with the old syntax mode.
                • Have you included references to all required assemblies?
                • Are you inside a #pragma unmanaged block? If so, you cannot (obviously) do managed stuff in there.

                Regards, Nish


                Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                The Ultimate Grid - The #1 MFC grid out there!

                A M 2 Replies Last reply
                0
                • A ALQallaf

                  nothing changes still have errors when i place MessageQueue^ theQueue = gcnew MessageQueue; inside my function SendToQueue()

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #8

                  You've told the compiler (via the pragmas) that SendToQueue() is unmanaged, yet you're trying to use managed code in it.

                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                  M 1 Reply Last reply
                  0
                  • M Michael Dunn

                    You've told the compiler (via the pragmas) that SendToQueue() is unmanaged, yet you're trying to use managed code in it.

                    --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                    M Offline
                    M Offline
                    Milton Karimbekallil
                    wrote on last edited by
                    #9

                    Yes, exactly .. he was trying to call managed code from unmanaged function. He got fixed creating a new managed cpp project. rgds...milton

                    1 Reply Last reply
                    0
                    • N Nish Nishant

                      ALQallaf wrote:

                      i tryed your syntax , but still having an errors nothing changed

                      Check the following :

                      • Are you using the old syntax? You cannot use C++/CLI with the old syntax mode.
                      • Have you included references to all required assemblies?
                      • Are you inside a #pragma unmanaged block? If so, you cannot (obviously) do managed stuff in there.

                      Regards, Nish


                      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                      The Ultimate Grid - The #1 MFC grid out there!

                      A Offline
                      A Offline
                      ALQallaf
                      wrote on last edited by
                      #10

                      Thanks Nishant Sivakumar its works now

                      1 Reply Last reply
                      0
                      • N Nish Nishant

                        ALQallaf wrote:

                        i tryed your syntax , but still having an errors nothing changed

                        Check the following :

                        • Are you using the old syntax? You cannot use C++/CLI with the old syntax mode.
                        • Have you included references to all required assemblies?
                        • Are you inside a #pragma unmanaged block? If so, you cannot (obviously) do managed stuff in there.

                        Regards, Nish


                        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                        The Ultimate Grid - The #1 MFC grid out there!

                        M Offline
                        M Offline
                        Milton Karimbekallil
                        wrote on last edited by
                        #11

                        Nish he was trying to call managed dll from an unmanged win32 dll. thats why the err. rgds..milton.

                        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