Thread View: comp.sys.mac.programmer.codewarrior
3 messages
3 total messages
Started by Jonathan Hoyle
Wed, 05 Nov 2003 23:11
Exporting a __stdcall function from a CodeWarrior .DLL
Author: Jonathan Hoyle
Date: Wed, 05 Nov 2003 23:11
Date: Wed, 05 Nov 2003 23:11
16 lines
1666 bytes
1666 bytes
I have a CodeWarrior .DLL project on Windows that I am trying to exporting some C functions from. The only problem is that they are __stdcall functions, not __cdeclspec functions. What is the protocol for doing this? I understand that I need to create an .exp or .def file containing them, but I do not see the format of this documented anywhere. If a function has say the following prototype: short __stdcall foo(short x); What is the proper syntax for exporting this from a CodeWarrior .DLL? And are there any examples out there that can show me how it is done? Jonathan Hoyle Gene Codes Corporation
Re: Exporting a __stdcall function from a CodeWarrior .DLL
Author: Ed Swartz
Date: Thu, 06 Nov 2003 19:35
Date: Thu, 06 Nov 2003 19:35
48 lines
3332 bytes
3332 bytes
Hi Jonathan, > I have a CodeWarrior .DLL project on Windows that I am trying to > exporting some C functions from. The only problem is that they are > __stdcall functions, not __cdeclspec functions. What is the protocol > for doing this? I understand that I need to create an .exp or .def > file containing them, but I do not see the format of this documented > anywhere. Check Targeting Windows under the "Creating Win32/x86 Dynamic Link Libraries" / "Function and Variable Names" / "Exporting names" section, or the "Module definitions file format" section. I admit the hierarchy is kind of weird, but all the details are there. > If a function has say the following prototype: > > short __stdcall foo(short x); > > What is the proper syntax for exporting this from a CodeWarrior .DLL? > And are there any examples out there that can show me how it is done? You don't need a .def/.exp file at all (these are legacy methods). Instead, simply add "__declspec(dllexport)" to the declaration: __declspec(dllexport) short __stdcall foo(short x); And the linker will automatically export it. In a client of the DLL you need __declspec(dllimport) instead. You can create a project from stationery (Win32 DLL) to see how to set up headers to declare the function the right way for the implementation and the client. If you really need to use a .def file, the easiest method is to specify: EXPORTS foo and the linker should export the symbol named foo, no matter what its calling convention is. In the event you have multiple symbols with this root name, or the linker can't find it, you'll get an error, and will have to use the actual symbol name, which for a C function is probably "_foo@4", but for C++ it's a lot hairier. You can disassemble the file defining foo to see what the symbol name is. (Anyway, just use the __declspec -- it's there to avoid all this crufty .def file nonsense). -- Ed
Re: Exporting a __stdcall function from a CodeWarrior .DLL
Author: Jonathan Hoyle
Date: Fri, 07 Nov 2003 19:12
Date: Fri, 07 Nov 2003 19:12
7 lines
1323 bytes
1323 bytes
Hi Ed, Your solution works for host applications written in Codewarrior; unfortunately, the host app in this case is written in Basic, so I don't have the __dllimport() option there. :-( Jonathan
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads