[Winpcap-users] RE: TCP/IP stack - reinventing the wheel

Bryan Kadzban bryan at kadzban.is-a-geek.net
Wed Aug 16 16:50:29 GMT 2006


On Wed, Aug 16, 2006 at 03:38:10PM +0000, Thomas O'Hare wrote:
> My last stumbling block is exporting functions in an easy as possible
> manner.
> 
> I know there are several methods (DEF, macro, etc), several types of of
> Libraries (static, dynamic, etc), but I just want the easiest, safest
> and fastest way to have my functions available to an external program.

I'd recommend doing a bit of reading (...like you haven't already!).
Specifically, this article written by Raymond Chen (shell and
back-compat guru at Microsoft):

http://blogs.msdn.com/oldnewthing/archive/2004/01/12/57833.aspx

Note especially these excerpts:

> The dllexport attribute tells the linker to generate an export table
> entry for the specified function. This export entry is decorated.

and:

> So if you intend people to be able to GetProcAddress for functions and
> you intend your code to be portable to multiple platforms, or if you
> intend them to be able to use your DLL from a language other than
> C/C++ or use a C++ compiler different from Microsoft Visual Studio,
> then you must export the function by its undecorated name.

The important part of that last bit is the "from a language other than
C/C++" part.  VB.net and C# (and any language that uses .net P/invoke)
calls into the DLL functions using the pointer returned by this
GetProcAddress API.  So if you intende to use a DLL from any .net
language using p/invoke, you'll have to export the undecorated names.

This is probably easiest if you use a .def file, and then omit the
DLLEXPORT macros and __declspec(dllexport) specifiers on the exported
functions.

You will have to create a dynamic library, not a static library.  Static
libraries link the DLL's code into each program that uses the library,
so you end up with multiple copies floating around all over the place as
a part of larger executables.  Dynamic libraries create DLL files, which
can be shared.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://www.winpcap.org/pipermail/winpcap-users/attachments/20060816/60b0c637/attachment.pgp


More information about the Winpcap-users mailing list