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. how can i export a function of a class?

how can i export a function of a class?

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
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 alphaxz

    hello all: i have a prolem to ask i want to creat a dll in this dll i hava a class i want to export the function of the class whether i can invoke the export function of the dll using c lanuage programmer?

    a beginner

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    See here.

    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

    M 1 Reply Last reply
    0
    • A alphaxz

      hello all: i have a prolem to ask i want to creat a dll in this dll i hava a class i want to export the function of the class whether i can invoke the export function of the dll using c lanuage programmer?

      a beginner

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #3

      I prefer something like this, using __declspec(dllexport)/__declspec(dllimport)... In a header file shared by both the DLL and other modules:

      // MyClass.h

      #if defined(BUILDING_MY_DLL)
      #define MY_DLL_IMP_EXP __declspec(dllexport)
      #else
      #define MY_DLL_IMP_EXP __declspec(dllimport)
      #endif

      class MyClass
      {
      public:
      MY_DLL_IMP_EXP int SomeFunc();
      };

      In the DLL code:

      #include "MyClass.h"

      int MyClass::SomeFunc()
      {
      return 12;
      }

      In the module importing the function

      #include "MyClass.h"

      MyClass mc;
      int ret = mc.SomeFunc();

      Add a define compiler option for BUILDING_MY_DLL (/D "BUILDING_MY_DLL") on the DLL project settings, but not on any projects that use the DLL. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • D David Crow

        See here.

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #4

        Broken link alert :)

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        A D 2 Replies Last reply
        0
        • M Mark Salsbery

          Broken link alert :)

          Mark Salsbery Microsoft MVP - Visual C++ :java:

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

          thanks all i got the method I use the class in a global function then i deifne the global function as export function

          a beginner

          M CPalliniC 2 Replies Last reply
          0
          • A alphaxz

            thanks all i got the method I use the class in a global function then i deifne the global function as export function

            a beginner

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #6

            alphaxz wrote:

            I use the class in a global function then i deifne the global function as export function

            If that's what you want. That's not the same as exporting a function of a class. That's like using C++ without classes - C. :) Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            1 Reply Last reply
            0
            • A alphaxz

              thanks all i got the method I use the class in a global function then i deifne the global function as export function

              a beginner

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #7

              WOW, C++ classes encapsulation with C global functions. Is that the C-nemesis pattern? :rolleyes:

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              In testa che avete, signor di Ceprano?

              M 1 Reply Last reply
              0
              • M Mark Salsbery

                Broken link alert :)

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #8

                Are you sure? It should go to James' post below.

                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                M 1 Reply Last reply
                0
                • D David Crow

                  Are you sure? It should go to James' post below.

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #9

                  I must have scrolled down too soon, before the post opened - sorry :)

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    WOW, C++ classes encapsulation with C global functions. Is that the C-nemesis pattern? :rolleyes:

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #10

                    We're not supposed to mention the C-nemesis pattern, are we? :)

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    CPalliniC 1 Reply Last reply
                    0
                    • M Mark Salsbery

                      We're not supposed to mention the C-nemesis pattern, are we? :)

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #11

                      It depends on the mood of the day. :-D

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                      In testa che avete, signor di Ceprano?

                      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