How to declare dl exports within dll cp?

This is a discussion on How to declare dl exports within dll cp? within the C++ Programming forums, part of the General Programming Boards category; Well i'm a newb when it comes to dll's it seem that you can either use a def file or ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    91

    How to declare dl exports within dll cp?

    Well i'm a newb when it comes to dll's it seem that you can either use a def file or declare the exports within the dll header file. Well this is just a starter dll.

    My def file has to contain this info,

    Code:
    LIBRARY "project1.dll"
    EXPORTS 
    xorString
    So how do i decalre this in the cpp instead Somewhere within this statement?

    Code:
    #ifndef _DLL_H_
    #define _DLL_H_
    
    #if BUILDING_DLL
    # define DLLIMPORT __declspec (dllexport)
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL *
    Last edited by joeyzt; 05-14-2004 at 06:02 PM.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can add the declspec to the function prototype. You probably also wish to use extern "C" to avoid C++ name mangling and __stdcall to allow Visual Basic to call your DLL.

    So:
    Code:
    int xorString(char * szIn);
    becomes
    Code:
    extern "C" DLLIMPORT int __stdcall xorString(char * szIn);
    You may wish to combine this into a macro:
    Code:
    #define DLLFUNCTION(retType) extern "C" DLLIMPORT retType __stdcall
    which you can use:
    Code:
    DLLFUNCTION(int) xorString(char * szIn);
    Make sure BUILDING_DLL is defined when you compile your DLL.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    I've just been readin up on calling conventions, it says you can either use,

    extern "C" __declspec(dllexport) void(etc) or,

    extern "C" int __stdcall , well in my dll i have tried,

    extern "C" __declspec(dllexport)

    void __stdcall funcmy(){

    and this works . Why is that ?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Why not? I don't know any reason that you can not combine __declspec(dllexport) with __stdcall. The first signifies that the function should be exported from the DLL while the latter tells the compiler to use the __stdcall calling convention.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 08:11 AM
  2. Dll Exports Question
    By todd14 in forum Windows Programming
    Replies: 2
    Last Post: 09-20-2007, 12:49 PM
  3. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 03:20 AM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 01:34 PM
  5. Enumerating Exports in a DLL...
    By minime6696 in forum Windows Programming
    Replies: 1
    Last Post: 04-04-2002, 04:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21