This is probably just a massive brain fart but if you declare a function with __declspec(dllexport) is it automatically __stdcall? does it not need to be explicit? trying them both together doesn't compile of course.
This is probably just a massive brain fart but if you declare a function with __declspec(dllexport) is it automatically __stdcall? does it not need to be explicit? trying them both together doesn't compile of course.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
I doubt it......C Compilers normally switch to __cdecl until told otherwise.....
__declspec(dllexport) is just a special (and more efficient) method of exporting symbols
Well that's what I'm asking then, are you able to export a __stdcall or other types with a __declspec.
for instance:
__declspec(dllexport) __stdcall int Func(int blah);
//this doesn't compile of course but it's the idea I'm going for.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
Have you tried -
__declspec (dllexport) int __stdcall Func(int blah);
Joe
Yeah...just tried it....
Code://The dll #include <windows.h> #include <iostream> void __declspec(dllexport) CallC(char* szText){ std::cout << szText << std::endl; } void __declspec(dllexport) __stdcall CallStd(char* szText){ std::cout << szText << std::endl; }The disassembly revealedCode:#include <windows.h> #pragma comment(lib,"TestDll.lib") void __declspec(dllimport) CallC(char* szText); void __declspec(dllimport) __stdcall CallStd(char* szText); int main() { CallC("Hello World"); CallStd("Hello World"); return 0; }
The normal declaration without __stdcall restored the stack - so its __cdecl.....and where I explicitly said __stdcall it didnt11: CallC("Hello World");
00401028 mov esi,esp
0040102A push offset string "Hello World" (0041f01c)
0040102F call dword ptr [__imp_?CallC@@YAXPAD@Z (00424290)]
00401035 add esp,4
00401038 cmp esi,esp
0040103A call __chkesp (00401090)
12:
13: CallStd("Hello World");
0040103F mov esi,esp
00401041 push offset string "Hello World" (0041f01c)
00401046 call dword ptr [__imp_?CallStd@@YGXPAD@Z (00424294)]
0040104C cmp esi,esp
0040104E call __chkesp (00401090)
Joe, you're so right. dang I'm an idiot. thanks.
further.... can you do a member function?
__declspec(dllexport) int __thiscall Func();
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
Originally posted by FillYourBrain
Well that's what I'm asking then, are you able to export a __stdcall or other types with a __declspec.
for instance:
__declspec(dllexport) __stdcall int Func(int blah);
//this doesn't compile of course but it's the idea I'm going for.
Oops...Your declarations are wrong..see my example
Hmm....never tried.....you can export a whole class thoughOriginally posted by FillYourBrain
Joe, you're so right. dang I'm an idiot. thanks.
further.... can you do a member function?
__declspec(dllexport) int __thiscall Func();
The only reason I'm doing all of this is because the only thing I ever usually export is a _cdecl function. I know that you can export classes and variables as well. Have you guys had any real experience with exporting classes? I've heard much about how horribly this has been implemented.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
Yes...you just need the class declaration in the module you which to import to....often you just reuse the headerOriginally posted by FillYourBrain
The only reason I'm doing all of this is because the only thing I ever usually export is a _cdecl function. I know that you can export classes and variables as well. Have you guys had any real experience with exporting classes? I've heard much about how horribly this has been implemented.
Code://dll #include <windows.h> #include <iostream> class __declspec(dllexport) foobar{ public: foobar(); ~foobar(); void Sing(); }; foobar::foobar(){ std::cout << "Constructor" << std::endl; } foobar::~foobar(){ std::cout << "Destructor" << std::endl; } void foobar::Sing(){ std::cout << "Lala" << std::endl; }Code:#include <windows.h> #pragma comment(lib,"TestDll.lib") class __declspec(dllimport) foobar{ public: foobar(); ~foobar(); void Sing(); }; int main() { foobar f; f.Sing(); return 0; }
Fordy, that's a static linking example... How would you dynamically link. I assume ::GetProcAddress() is not very useful for non functions.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
Hmm...not sure.....normally, in examples where they want to export class methods I have seen people wrap them in a func....might very well be a method, but I cant think of one right now...Originally posted by FillYourBrain
Fordy, that's a static linking example... How would you dynamically link. I assume ::GetProcAddress() is not very useful for non functions.
If not, I can't really see doing it. Creating COM-like interfaces and passing them over seems like a better method (that's what I've always done).
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
although, there may be a way of "re-assembling" a class by exporting the methods as I mentioned above. Then you could fill in a class to derive from with virtual function pointers from the dll. That would be very strange but it seems like it might work.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
See www.bcbdev.com/articles/vcdll2.htm
This excellent. Ignore references to VCL v BCB, it's just talking about exporting objects from a DLL & how do it from the ground up.
If you need inheritence, let me know.