Silver: Quote:
What happens if you reorder it |
Again, a class is just an extension of a structure. The functions (object methods) are not included in the class definition, but are compiled as external code. So the order in class member definitions is irrelevant.
Try to compile this snippet:
Code:
#include <iostream>
using namespace std;
class c0 {
public:
c0(); // constructor to be imported
~c0(); // destructor to be imported
//...methods to be imported...
private:
char dummy[2000];
};
class c1 {
private:
char dummy[2000];
public:
c1(); // constructor to be imported
~c1(); // destructor to be imported
//...methods to be imported...
};
void
main(void)
{
cout << sizeof(c0) << "," << sizeof(c1) << endl;
}
Both c0 and c1 will have a size of 2000 bytes!
TQN
Quote:
We can use a class exported in a DLL. I have tried and successed. |
Not exactly. Try to compile this:
Code:
/* bilbo 6jul04 - compile as cl -W3 -GX -LD try.cpp */
#include <iostream>
using namespace std;
class
__declspec(dllexport)
c {
private:
public:
int m_i;
c();
void prt(void);
};
c::c()
{
m_i = 777;
}
void
c:

rt(void)
{
cout << m_i << endl;
}
You are feeling all the class is being exported, isn't it? But look at the exports of your resulting DLL: They are three:
Code:
??0c@@QAE@XZ __thiscall c::c(void)
??4c@@QAEAAV0@ABV0@@Z class c & __thiscall c:

perator=(class c const &

?prt@c@@QAEXXZ void __thiscall c:

rt(void)
Only the functions were exported. The concept of class has gone away: no space for member m_i. (Incidentally, an assignment function was inferred by the compiler, the second one).
Quote:
place a __declspec(dllimport) to the class define. |
__declspec(dllimport) is not needed in the calling program. Try this:
Code:
#pragma comment(lib, "trydll"
class c {
char dummy[2000];
public:
c();
void prt(void);
};
void
main(void)
{
c cc;
cc.prt();
}
In both cases (with or without __declspec(dllimport)) the two functions related to class c (the constructor and the method prt()) will be placed in the IMPORTS section of the executable.
acane
Quote:
That DLL2Lib tool is excellent. |
Yup, not so bad. But you need some knowledge of the DLL to use it from your application, exactly as in the case you do not use DLL2LIB.
Regards, bilbo