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. Help with this basic code

Help with this basic code

Scheduled Pinned Locked Moved Managed C++/CLI
helptutorial
4 Posts 3 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.
  • F Offline
    F Offline
    Fu Manchu
    wrote on last edited by
    #1

    hi, i am having some trouble with this basic example code, i can't figure out why i am getting an error, null reference! please help thanks #include "stdafx.h" #using mscorlib.dll using namespace std; class Foo { public: Foo(); ~Foo(); void DoSomeFoo(); }; // constructor Foo::Foo() { cout<<"Constructor called!"<DoSomeFoo(); } int _tmain() { MFoo*myfoo; myfoo->ManagedDoSomeFoo(); return 0; }

    T G F 3 Replies Last reply
    0
    • F Fu Manchu

      hi, i am having some trouble with this basic example code, i can't figure out why i am getting an error, null reference! please help thanks #include "stdafx.h" #using mscorlib.dll using namespace std; class Foo { public: Foo(); ~Foo(); void DoSomeFoo(); }; // constructor Foo::Foo() { cout<<"Constructor called!"<DoSomeFoo(); } int _tmain() { MFoo*myfoo; myfoo->ManagedDoSomeFoo(); return 0; }

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      where in the code are you getting this error, and what does the error message say ? does it happen at runtime or before ?

      1 Reply Last reply
      0
      • F Fu Manchu

        hi, i am having some trouble with this basic example code, i can't figure out why i am getting an error, null reference! please help thanks #include "stdafx.h" #using mscorlib.dll using namespace std; class Foo { public: Foo(); ~Foo(); void DoSomeFoo(); }; // constructor Foo::Foo() { cout<<"Constructor called!"<DoSomeFoo(); } int _tmain() { MFoo*myfoo; myfoo->ManagedDoSomeFoo(); return 0; }

        G Offline
        G Offline
        Gavin Taylor
        wrote on last edited by
        #3

        Your never actually creating an instance of myfoo, try changing your _tmain to:

        int _tmain()
        {
        MFoo*myfoo = new MFoo( ); // Create an instance of this object
        myfoo->ManagedDoSomeFoo();
        return 0;
        }

        Gavin Taylor w: http://www.gavspace.com -- modified at 5:39 Wednesday 8th March, 2006

        1 Reply Last reply
        0
        • F Fu Manchu

          hi, i am having some trouble with this basic example code, i can't figure out why i am getting an error, null reference! please help thanks #include "stdafx.h" #using mscorlib.dll using namespace std; class Foo { public: Foo(); ~Foo(); void DoSomeFoo(); }; // constructor Foo::Foo() { cout<<"Constructor called!"<DoSomeFoo(); } int _tmain() { MFoo*myfoo; myfoo->ManagedDoSomeFoo(); return 0; }

          F Offline
          F Offline
          Fu Manchu
          wrote on last edited by
          #4

          thanks guys, i thought it was something like that,but i mainly use vb.net so i get a little stuck with c++. i have been trying to wrap this example, so i can practice for a much bigger program. i have never done this before and the help on the net is a little vague, i need a very very basic walkthrough, because the ones i have found won't compile, and its hard enough trying to debug code that you dont really understand. i know this much.... i have a class library(.net) called fooManaged and its automatical created fooManaged.h. and i created UnManaged.h in the UnManaged.h file i have this code..... #include iostream #include vcclr.h using namespace std; class Foo { public: Foo(); ~Foo(); void DoSomeFoo(); }; // constructor Foo::Foo() { cout<<"Constructor called!"< in fooManaged.h i have this code.... `// fooManaged.h #pragma once using namespace System; namespace fooManaged { public __gc class MFoo { private: Foo * _foo; public: MFoo(); ~MFoo(); void ManagedDoSomeFoo(); }; // constructor MFoo::MFoo() { _foo = new Foo(); } // destructor MFoo::~MFoo() { delete _foo; } // method void MFoo::ManagedDoSomeFoo() { _foo->DoSomeFoo(); } }` the fooManaged.cpp file just has... #include "stdafx.h" #include "Unmanagedfoo.h" #include "fooManaged.h" #using mscorlib.dll it all compiles...but there is a big linking error!! Compiling... fooManaged.cpp Linking... LINK : error LNK2020: unresolved token (0A000005) _CxxThrowException LINK : error LNK2020: unresolved token (0A000019) free LINK : error LNK2020: unresolved token (0A00001A) strlen LINK : error LNK2020: unresolved token (0A00001B) memmove LINK : error LNK2020: unresolved token (0A00001C) memcpy LINK : error LNK2020: unresolved token (0A00001D) delete LINK : fatal error LNK1120: 6 unresolved externals i must be doing something wrong, some help with this will be very wecome thanks

          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