how can i export a function of a class?
-
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
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
-
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
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)
#endifclass 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:
-
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
Broken link alert :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Broken link alert :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
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
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:
-
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
WOW,
C++
classes encapsulation withC
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 -
Broken link alert :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
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
-
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
I must have scrolled down too soon, before the post opened - sorry :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
WOW,
C++
classes encapsulation withC
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 ClarkeWe're not supposed to mention the C-nemesis pattern, are we? :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
We're not supposed to mention the C-nemesis pattern, are we? :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
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