سؤال

I am trying to write a LSP for winsock and as per MSDN documentation the dll is supposed to export a single function viz. WSPStartup() as defined in Ws2spi.h

While compiling I get an error:

error C2375: 'WSPStartup' : redefinition; different linkage

If I append the

__declspec(dllexport) 

directive to it. On the other hand, if I use the

__control_entrypoint(DllExport)

it compiles fine, but the function is not actually exported. I checked using dependency viewer. To make sure that other LSP implementations export the functions or not, I used dependency viewer on VMWares vsocklib.dll and mswsock.dll, both dlls export the said 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 do I make a DLL which exports the WSPStartup() function ??

هل كانت مفيدة؟

المحلول

Since the function prototype is given in the Ws2spi.h file, adding any kind of additional specifiers to the function in the definition will cause the compiler to give the 'redefinition' error.

Also it is not possible to have it exported directly via declspec(dllexport) which will create a decorated name since WSPAPI specifier declares the function as a stdcall.

To mitigate all these problems I exported the method by a DEF file as shown in this article - Exporting from a DLL Using DEF Files

I believe that is the only proper method to get an undecorated WSPStartup() function export in your dll.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top