Unable to set WSPStartup as dll export

I am trying to write LSP for winsock, and according to the MSDN documentation, dll should export one function, namely. WSPStartup (), as defined in Ws2spi.h

When compiling, I get an error message:

error C2375: 'WSPStartup' : redefinition; different linkage 

If I add

 __declspec(dllexport) 

. On the other hand, if I use

 __control_entrypoint(DllExport) 

It compiles fine, but the function is not actually exported. I checked the use of the dependency viewer. To make sure that other LSP implementations export functions or not, I used the dependency viewer on VMWares vsocklib.dll and mswsock.dll, both dll libraries exported the specified function.

My sample implementation is as follows: -

 // dllmain.cpp : Defines the entry point for the DLL application. #include "stdafx.h" #include <Ws2spi.h> BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } __declspec(dllexport) __checkReturn int WSPAPI WSPStartup( __in WORD wVersionRequested, __in LPWSPDATA lpWSPData, __in LPWSAPROTOCOL_INFOW lpProtocolInfo, __in WSPUPCALLTABLE UpcallTable, __out LPWSPPROC_TABLE lpProcTable ) { return 0; } 

So what am I doing wrong here? How to create a DLL that exports the WSPStartup () function?

+4
source share
1 answer

Since the prototype of the function is specified in the Ws2spi.h file, adding any additional qualifiers to the function in the definition will cause the compiler to fail with an "override" error.

It is also not possible to directly export it through declspec (dllexport), which will create a decorated name, because the WSPAPI specifier declares this function as stdcall.

To fix all these problems, I exported this method using a DEF file, as shown in this article. Export from DLL using DEF files

I believe this is the only correct method to get the unecorated WSPStartup () function in your DLL.

+3
source

All Articles