473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to expose API from executable?

emibt08
25
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
Aug 30 '09 #1

✓ answered by unauthorized

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.

1 4688
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.
Aug 30 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jay Haslup | last post by:
I am trying to figure out how to get the CMD (dos) window to come up when I call a executable. I have this working on a Win2000/apache machine and am trying to use the same code on a identical...
17
by: Filipe Martins | last post by:
Hello. I've read somewhere that the executable is smaller if we use a source file for each function! So, I tested this with gcc and it seams to confirm! What seams to happen is that if we call...
7
by: Johnny | last post by:
How do I create a link on a Web page on my hard drive that will run an executable file on my hard drive? For example, let's say I create runpoodle.htm and save it to my hard drive, and let's...
8
by: suresh_C# | last post by:
Dear All, What is difference between Portable Executable (PE) file and a Assembly? Thanks, Mahesh
6
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like...
3
by: Miguel Ferreira via .NET 247 | last post by:
Hi ! I have developed a class Library with several classes and methods. Its working fine with a windows forms test application, but now i need to create a webservice that will expose those...
34
by: priyanka | last post by:
Hi, I was wondering if we could parse or do something in the executable( whose source language was C). How can I use some scripting language like perl/python to find out the information about...
3
by: Mo | last post by:
Hi, Is there a way to include an executable (xxx.exe) file inside a c# console project so that the resulting project binary have only one final executable file? My c# console application is...
16
by: Erwin Moller | last post by:
Why is a binary file executable? Is any binary file executable? Is only binary file executable? Are all executable files binary? What is the connection between the attribute of binary and that of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.