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. C / C++ / MFC
  4. Exporting Classes

Exporting Classes

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
3 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.
  • P Offline
    P Offline
    Peter Liddle
    wrote on last edited by
    #1

    Hey Guys I have been trying to export a class from a DLL for ages now and had little luck could someone post a quick example or tutorial on how to export a class. Peter

    P T 2 Replies Last reply
    0
    • P Peter Liddle

      Hey Guys I have been trying to export a class from a DLL for ages now and had little luck could someone post a quick example or tutorial on how to export a class. Peter

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      This example was generated by the app wizards for a DLL. Here is the header file:

      // The following ifdef block is the standard way of creating macros which make exporting
      // from a DLL simpler. All files within this DLL are compiled with the EXAMPLE_EXPORTS
      // symbol defined on the command line. this symbol should not be defined on any project
      // that uses this DLL. This way any other project whose source files include this file see
      // EXAMPLE_API functions as being imported from a DLL, wheras this DLL sees symbols
      // defined with this macro as being exported.
      #ifdef EXAMPLE_EXPORTS
      #define EXAMPLE_API __declspec(dllexport)
      #else
      #define EXAMPLE_API __declspec(dllimport)
      #endif

      // This class is exported from the example.dll
      class EXAMPLE_API CExample {
      public:
      CExample(void);
      // TODO: add your methods here.
      };

      extern EXAMPLE_API int nExample;

      EXAMPLE_API int fnExample(void);

      Here is the cpp file:

      // example.cpp : Defines the entry point for the DLL application.
      //

      #include "stdafx.h"
      #include "example.h"

      BOOL APIENTRY DllMain( HANDLE hModule,
      DWORD ul_reason_for_call,
      LPVOID lpReserved
      )
      {
      switch (ul_reason_for_call)
      {
      case DLL_PROCESS_ATTACH:
      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
      case DLL_PROCESS_DETACH:
      break;
      }
      return TRUE;
      }

      // This is an example of an exported variable
      EXAMPLE_API int nExample=0;

      // This is an example of an exported function.
      EXAMPLE_API int fnExample(void)
      {
      return 42;
      }

      // This is the constructor of a class that has been exported.
      // see example.h for the class definition
      CExample::CExample()
      {
      return;
      }

      Good Luck!


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      1 Reply Last reply
      0
      • P Peter Liddle

        Hey Guys I have been trying to export a class from a DLL for ages now and had little luck could someone post a quick example or tutorial on how to export a class. Peter

        T Offline
        T Offline
        Tom Archer
        wrote on last edited by
        #3

        class AFX_EXT_CLASS CMyClass { ... } Cheers, Tom Archer Author, Inside C# Author, Visual C++.NET Bible A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af

        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