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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Beginner question

Beginner question

Scheduled Pinned Locked Moved Managed C++/CLI
c++questioncsharpvisual-studiotesting
6 Posts 5 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.
  • J Offline
    J Offline
    Jose Vicente
    wrote on last edited by
    #1

    Hello. I'm a beginner in working with Managed C++ and I have a question. I have read that it's possible to mix managed and unmanaged code in the same application, and I have been testing this. I have created a simple Windows Form application and do some little things. Then I have tryed to use a class that's its written in unmanaged C++ that make some things with CStrings. After I have compiled this file ( I only added some includes to make it work ) I tried to use some functions of this class in my form file. So when I added the include to this class, and build the application some error messages appear like this: " error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager' stdafx.cpp(0) : see declaration of 'System::Resources::ResourceManager' " In the error line the code that the Visual Studio wizard wrote it's this : "this->imageList1->ImageStream = (__try_cast(resources->GetObject(S"imageList1.ImageStream")));" As you can see there is not GetObjetA call, instead its GetObject. Any idea ? Thanks. :confused:

    S 1 Reply Last reply
    0
    • J Jose Vicente

      Hello. I'm a beginner in working with Managed C++ and I have a question. I have read that it's possible to mix managed and unmanaged code in the same application, and I have been testing this. I have created a simple Windows Form application and do some little things. Then I have tryed to use a class that's its written in unmanaged C++ that make some things with CStrings. After I have compiled this file ( I only added some includes to make it work ) I tried to use some functions of this class in my form file. So when I added the include to this class, and build the application some error messages appear like this: " error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager' stdafx.cpp(0) : see declaration of 'System::Resources::ResourceManager' " In the error line the code that the Visual Studio wizard wrote it's this : "this->imageList1->ImageStream = (__try_cast(resources->GetObject(S"imageList1.ImageStream")));" As you can see there is not GetObjetA call, instead its GetObject. Any idea ? Thanks. :confused:

      S Offline
      S Offline
      Slaru
      wrote on last edited by
      #2

      Hi I had this same question earlier and someone told me that linkers are stupid. That's what I'll tell you because I am a newbie. The solution to your question is to undefine GetObject like so: #undef GetObject If you use System::Windows::Forms::MessageBox you will also need to undefine it. Hope that helped and if anyone could explain why this is that would be great.

      J M N 3 Replies Last reply
      0
      • S Slaru

        Hi I had this same question earlier and someone told me that linkers are stupid. That's what I'll tell you because I am a newbie. The solution to your question is to undefine GetObject like so: #undef GetObject If you use System::Windows::Forms::MessageBox you will also need to undefine it. Hope that helped and if anyone could explain why this is that would be great.

        J Offline
        J Offline
        Jose Vicente
        wrote on last edited by
        #3

        Thank you very much;P

        1 Reply Last reply
        0
        • S Slaru

          Hi I had this same question earlier and someone told me that linkers are stupid. That's what I'll tell you because I am a newbie. The solution to your question is to undefine GetObject like so: #undef GetObject If you use System::Windows::Forms::MessageBox you will also need to undefine it. Hope that helped and if anyone could explain why this is that would be great.

          M Offline
          M Offline
          monrobot13
          wrote on last edited by
          #4

          Since you're using CString in your umanaged project you're using MFC. Throught the MFC library there are many #defines in order for code to be compiled using either Ascii characters or Wide characters. When you complie your code the library will check what type of strings you should be compiling for and will then use the appropriate function. For you it was "GetObjectA" meaning your code was trying to compile using 16bit characters. You have to do it for the message box as well because it has both MessageBoxA and MessageBoxW functions so it can complie using either Ascii or Wide strings. I hope that made some sense. I'm not sure if that's completely right, as I'm not a pro programmer or anything. - monrobot13

          J 1 Reply Last reply
          0
          • M monrobot13

            Since you're using CString in your umanaged project you're using MFC. Throught the MFC library there are many #defines in order for code to be compiled using either Ascii characters or Wide characters. When you complie your code the library will check what type of strings you should be compiling for and will then use the appropriate function. For you it was "GetObjectA" meaning your code was trying to compile using 16bit characters. You have to do it for the message box as well because it has both MessageBoxA and MessageBoxW functions so it can complie using either Ascii or Wide strings. I hope that made some sense. I'm not sure if that's completely right, as I'm not a pro programmer or anything. - monrobot13

            J Offline
            J Offline
            Joey Bloggs
            wrote on last edited by
            #5

            I'm not sure on the .net stuff still learning it myself. But from an MFC perspective xxxA is ascii ie 8bit chars whilst xxxW is unicode ucs16 ie 16bit characters. The normal way to control this is with a preprocessor define of MBCS or UNICODE. (MultiByteCharSet is just ascii 8bit characters with an escape character defined to encode further characters with a second 8bit character)

            1 Reply Last reply
            0
            • S Slaru

              Hi I had this same question earlier and someone told me that linkers are stupid. That's what I'll tell you because I am a newbie. The solution to your question is to undefine GetObject like so: #undef GetObject If you use System::Windows::Forms::MessageBox you will also need to undefine it. Hope that helped and if anyone could explain why this is that would be great.

              N Offline
              N Offline
              Nemanja Trifunovic
              wrote on last edited by
              #6

              Slaru wrote: someone Me Slaru wrote: told me that linkers are stupid No, I told you preprocessors are stupid. Somewhere in windows.h there is a preprocessor directive to turn every MessageBox into MessageBoxA or MessageBoxW, depending on whether it is a Unicode or non-Unicode build. Now, the *stupid* preprocessor does not know that your MessageBox is .NET MessageBox and not Win32 API MessageBox, and it turns System::Windows::Forms::MessageBox to System::Windows::Forms::MessageBoxA.

              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