Thread: How I properly declare an exported function that is also used locally?

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    How I properly declare an exported function that is also used locally?

    Hi,
    I have a FuncA() inside the EXE. FuncA() is called from inside the EXE and from inside a DLL. Therefore, I wrote a callback function for FuncA() so that the DLL can call to it. Hence, I need to export FuncA() so that I can get the function address from inside the DLL.
    Code:
    declspec(dllexport) void FuncA(){ return; }//declspec(dllexport) is to be able to get the function address.
    However,
    Because FuncA() is called from DLL AND from inside the EXE as well,
    my problem is the declaration of funcA() inside the EXE. That declaration will be used by the functions inside the EXE.
    Code:
    void FuncA();//If I write it this way I get the following error:
    error C2375: 'FuncA' : redefinition; different linkage
    And,
    Code:
    declspec(dllimport) void FuncA();//If I write it this way, I get the following warning and the program hangs.
    warning LNK4049: locally defined symbol _FuncA imported
    How do I write the proper declaration?
    Note: Windows, Visual Studio 2008, Standard-C
    Last edited by kenney00100; 03-08-2011 at 02:15 AM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    If you are exporting a function, it should be in the DLL not the exe.

    Calling it from the exe is then done through the .h and .lib generated when the DLL is compiled.

    Using it inside the DLL should be a simple matter of calling it.

    EXE (i.e. programs) do not normally export functions.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    Quote Originally Posted by CommonTater View Post
    If you are exporting a function, it should be in the DLL not the exe.

    Calling it from the exe is then done through the .h and .lib generated when the DLL is compiled.

    Using it inside the DLL should be a simple matter of calling it.

    EXE (i.e. programs) do not normally export functions.
    Thanks for the reply,
    I am exporting the function from the EXE just so that I can use a callback function inside the DLL. Without the __declspec(dllexport)FuncA() the function address will be unretrievable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in returning value from the dll exported function
    By dattaforit in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2006, 04:30 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

Tags for this Thread