How to expose API from executable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emibt08
    New Member
    • Oct 2008
    • 25

    How to expose API from executable?

    Hello,
    I have an application which is a server. Then, a client connects to it through a socket connection. Now, the thing is that I want to make a web front-end for the server, so the web interface will have almost the same functionality as my client application.
    I think that the best approach would be to expose API from my server and then use it for communication. For example, the web back-end (which would be located at the same box as the server) uses a dll with all functions and communicates that way instead of opening a socket connection to localhost.
    The problem is that I am not really sure how to design it. Like.. how would the dll connect to the server application (exe) and communicate with it. Maybe I am missing something here... however, any suggestion would be much appreciated.
    Thank you
  • unauthorized
    New Member
    • May 2009
    • 81

    #2
    This is OS dependant. Seeing how you talk about "exe" application, I will go ahead and assume you work under Windows.
    To expose a function to be imported in 3rd party libraries, you need:
    - a DLL which contains the API functions you wish to expose. All objects/functions that need to be accessed from outside the DLL must be declared with __declspec (dllexport) (for Visual Studio, different compilers may work differently) .
    - a static Lib to tell the linker how to connect to the DLL. Your linker will generate this automatically from the DLL. Alternatively you can use __declspec (import) (again, this is msvc specific) in your header to specify linkage
    - a header file that declares all exposed objects and functions.

    Refer to MSDN for detailed documentation, on how to do that. You will also have to look up you compiler's docs (if you aren't using VC) for details on how to specify linkage options for your functions.
    Link: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    There are many ways to have your DLL notify it's client app when an API call has occured, the easiest being a simple signal.

    You could also go with just a static library that contains the full executable code and a header file with declarations, but there are numerous drawbacks to this approach. I don't recommend it.

    Comment

    Working...