🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #642

Re: Exporting a __stdcall function from a CodeWarrior .DLL

#642
From: Ed Swartz
Date: Thu, 06 Nov 2003 19:35
48 lines
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
Technical Details
Message-ID: <boe7tg$fkd$1@newshost.mot.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!peer01.cox.net!peer02.cox.net!cox.net!newsfeed2.easynews.com!newsfeed1.easynews.com!easynews.com!easynews!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed1.sea.pnap.net!newsfeed.pnap.net!newsgate.mot.com!newshost.mot.com!not-for-mail
References: <bc8cf544.0311051511.5622d288@posting.google.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f635e,df2feb09e2571cfb
X-Google-Attributes: gidf635e,public
X-Google-Thread: 10bcce,df2feb09e2571cfb
X-Google-Attributes: gid10bcce,public
X-Google-Thread: fd047,df2feb09e2571cfb
X-Google-Attributes: gidfd047,public
X-Google-ArrivalTime: 2003-11-06 11:49:01 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!peer01.cox.net!peer02.cox.net!cox.net!newsfeed2.easynews.com!newsfeed1.easynews.com!easynews.com!easynews!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed1.sea.pnap.net!newsfeed.pnap.net!newsgate.mot.com!newshost.mot.com!not-for-mail
From: "Ed Swartz" <eswartz@antispam.metrowerks.com>
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.windows,codewarrior.mac
Subject: Re: Exporting a __stdcall function from a CodeWarrior .DLL
Date: Thu, 6 Nov 2003 13:35:50 -0600
Organization: Motorola
Lines: 51
Message-ID: <boe7tg$fkd$1@newshost.mot.com>
References: <bc8cf544.0311051511.5622d288@posting.google.com>
NNTP-Posting-Host: 10.82.188.214
X-Trace: newshost.mot.com 1068147440 16013 10.82.188.214 (6 Nov 2003 19:37:20 GMT)
X-Complaints-To: motpost1@azmsg.mot.com
NNTP-Posting-Date: 6 Nov 2003 19:37:20 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4927.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200