locked
Create DLL from LIB - HowTo ? RRS feed

  • Question

  • Simple problem here with VC++ Express... I'm very new to MS' compilers.

    Lets say we have a LIB here, containing a single function:

    Code Snippet

    DWORD WINAPI P9Open(IN OUT P9OpenContext *ctx);



    Don't care what P9OpenContext really is. My goal now is to create a DLL which includes this LIB and this function and exports this function.
    After having some trouble getting VC++ Express to create a DLL (thanks to this forum and his valuable Tips) I created a .h-File:

    Code Snippet

    extern "C" __declspec(dllexport) DWORD WINAPI P9Open(P9OpenContext *ctx);


    I did not build a function "P9Open" in my .cpp, as I do not want to export a new function created by myself. However, compiling and linking ends with 0 Errors and 0 Warnings... But my DLL simpliy does not contain "P9Open".

    What am I doing wrong ?

    Thanks and Greets from Germany,

    Olaf

    Sunday, April 29, 2007 7:20 AM

Answers

  • You have to wrap it.

    In your case it would be like this.

    extern"C" __declspec(dllexport) DWORD WINAPI P9OpenWrap(P9OpenContext *ctx)
    {
        return P9Open(ctx);
    }


    This is because the library and the dll have different linkage. I tried giving dllexport linkage to the lib version but it loses it along the way, so the only way to get this to work is to wrap it so there is one physically in the dll and it has export linkage.
    Sunday, April 29, 2007 1:23 PM

All replies

  • You have to wrap it.

    In your case it would be like this.

    extern"C" __declspec(dllexport) DWORD WINAPI P9OpenWrap(P9OpenContext *ctx)
    {
        return P9Open(ctx);
    }


    This is because the library and the dll have different linkage. I tried giving dllexport linkage to the lib version but it loses it along the way, so the only way to get this to work is to wrap it so there is one physically in the dll and it has export linkage.
    Sunday, April 29, 2007 1:23 PM
  • Thanks a lot, this worked fine for me.

    Olaf

    Monday, April 30, 2007 12:08 AM