CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 1999
    Posts
    19

    Use class from DLL?

    Hiya!

    I want in my main program use a class that is in a DLL. Is that possible?
    What kind of dll should my class be and how do I use it from the main program?
    I would like to do something like this.
    myClassFromDll myClass;
    myClass.SomeMethod();

    Thanks
    Magnus


  2. #2
    Join Date
    May 1999
    Posts
    116

    Re: Use class from DLL?

    If you are using an MFC entension DLl declare your class as follows:class AFX_EXT_CLASS CMyClassInDll
    {
    ....
    };

    If a normal dll use:class _declspec(dllexport) CMyClassInDll
    {
    ....
    };




  3. #3
    Join Date
    May 1999
    Location
    Bogotá, Colombia
    Posts
    37

    Re: Use class from DLL?

    Essentially you need to declare your class with the __declspec( dllexport ) modifier.

    This is what I do:

    //header file for class

    #ifdef MYCLASS_DLL_BUILD
    #define EXPORTED_DLL __declspec( dllexport )
    #else
    #define EXPORTED_DLL
    #endif

    class EXPORTED_DLL MyClass
    {
    //class declaration etc
    };




    I put the header file in a central location. I make sure that MYCLASS_DLL_BUILD is defined in the project where I build the .dll file and make sure that is not defined in the project where I actually use an insance of the class.

    Hope this helps

    Andrew





  4. #4
    Join Date
    Mar 1999
    Posts
    19

    Re: Use class from DLL?

    Okej thanks!

    But how do I use this class from my main program? Shall I link the obj file?

    /Magnus


  5. #5
    Join Date
    May 1999
    Posts
    116

    Re: Use class from DLL?

    You will need to include the header file for the class and also link your application with the .lib file created when you compiled your dll. (See VC help on linking to lib's)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured