digitalmars.D - DLL with same conventions as VC++
- Gilles G. (13/13) Jun 20 2007 Hello,
- torhu (5/19) Jun 20 2007 Did you check out the example in dmd\samples\mydll?
- Gilles G. (8/32) Jun 20 2007 Yes, of course!
- torhu (3/36) Jun 20 2007 Do you still have problems? Please post the exact error messages you
- torhu (3/3) Jun 20 2007 By the way, if you're trying to call C++ code from D, it has to be
- Gilles G. (16/19) Jun 21 2007 I enventually managed to make it work...
- Hoenir (2/7) Jun 21 2007 I think the symbols are mangled differently.
Hello,
I am trying to build a dll using D.
In my first attempt to write it in C++, I add working calls with the main
application by using something like:
int __stdcall DLLVersion(){return 1;}
this also only worked with VC++ using a .def file like (couldn't manage to make
it work using borland):
EXPORTS
DLLVersion
As I read the documentation, I understand (not sure) that in order to have
equivalent calls, I must use:
export extern(Windows) int DLLVersion(){return 1;}
The problem is that the main application doesn't seem torecognize the D DLL.
Any help would be fantastic!
--
Gilles
Jun 20 2007
Gilles G. wrote:Hello, I am trying to build a dll using D. In my first attempt to write it in C++, I add working calls with the main application by using something like: int __stdcall DLLVersion(){return 1;} this also only worked with VC++ using a .def file like (couldn't manage to make it work using borland): EXPORTS DLLVersion As I read the documentation, I understand (not sure) that in order to have equivalent calls, I must use: export extern(Windows) int DLLVersion(){return 1;}That looks correct to me.The problem is that the main application doesn't seem torecognize the D DLL. Any help would be fantastic!Did you check out the example in dmd\samples\mydll? And this page? http://www.digitalmars.com/d/dll.html
Jun 20 2007
torhu Wrote:Gilles G. wrote:Yes, of course! I use the same method: export and .def file. I understood the following: export extern(Windows) <=> __stdcall export extern(C) <=> __cdecl Does anybody have any idea what could be the (subtle) difference? Thanks!Hello, I am trying to build a dll using D. In my first attempt to write it in C++, I add working calls with the main application by using something like: int __stdcall DLLVersion(){return 1;} this also only worked with VC++ using a .def file like (couldn't manage to make it work using borland): EXPORTS DLLVersion As I read the documentation, I understand (not sure) that in order to have equivalent calls, I must use: export extern(Windows) int DLLVersion(){return 1;}That looks correct to me.The problem is that the main application doesn't seem torecognize the D DLL. Any help would be fantastic!Did you check out the example in dmd\samples\mydll? And this page? http://www.digitalmars.com/d/dll.html
Jun 20 2007
Gilles G. wrote:torhu Wrote:Do you still have problems? Please post the exact error messages you get, in English. And maybe your source code and command lines too.Gilles G. wrote:Yes, of course! I use the same method: export and .def file. I understood the following: export extern(Windows) <=> __stdcall export extern(C) <=> __cdecl Does anybody have any idea what could be the (subtle) difference?Hello, I am trying to build a dll using D. In my first attempt to write it in C++, I add working calls with the main application by using something like: int __stdcall DLLVersion(){return 1;} this also only worked with VC++ using a .def file like (couldn't manage to make it work using borland): EXPORTS DLLVersion As I read the documentation, I understand (not sure) that in order to have equivalent calls, I must use: export extern(Windows) int DLLVersion(){return 1;}That looks correct to me.The problem is that the main application doesn't seem torecognize the D DLL. Any help would be fantastic!Did you check out the example in dmd\samples\mydll? And this page? http://www.digitalmars.com/d/dll.html
Jun 20 2007
By the way, if you're trying to call C++ code from D, it has to be extern "C" functions. C++ symbols are mangled differently than D or C symbols.
Jun 20 2007
I enventually managed to make it work...
It appeared that the problem wasn't the dll export convention.
I discarded some of the function I exported and now the dll is well recognised
by the main app.
Just to be exhaustive:
To have a VC++ compatible dll interface, one just need to put
extern(Windows) in front of the function declaration instead of __stdcall in
the function declaration.
You also have to use a .def file were the names of the functions you want to
export are listed like:
EXPORTS
MyFunction1
MyFunction2
Use the DllMain function (copy/paste) given here:
http://www.digitalmars.com/d/dll.html
Thanks a lot for your help!
--
Gilles
torhu Wrote:
By the way, if you're trying to call C++ code from D, it has to be
extern "C" functions. C++ symbols are mangled differently than D or C
symbols.
Jun 21 2007
Gilles G. wrote:I understood the following: export extern(Windows) <=> __stdcall export extern(C) <=> __cdecl Does anybody have any idea what could be the (subtle) difference?I think the symbols are mangled differently.
Jun 21 2007









Gilles G. <schaouette free.fr> 