How to hide helper functions from open API in c

I am working on a project and I need to create an API. I use sockets to communicate between the server (my application) and clients (other applications using my API).

This project is in c not C ++

I come from a linux background, and this is my first project using the Windows libraries, Visual Studio 2008 and the DLL.

I have a connection between client and server, but I have some that are duplicated in both projects. I would like to create a library (possibly a dll file) that both projects can reference, so I don't need to support additional code.

I also need to create a library that has an API that I need to make available to my clients. The API functions that I want to publish have calls to these helper functions, which are “duplicated code,” I don’t want to expose these functions to my client, but I want my server to be able to use these functions. How can i do this?

I will try to clarify an example. This is where I started.

Server project:

int Server_GetPacket(SOCKET sd);
int ReceiveAll(SOCKET sd, char *buf, int len);
int VerifyLen(char *buf);

Client project:

int Client_SendCommand(int command);
int Client_GetData(int command, char *buf, int len);
int ReceiveAll(SOCKET sd, char *buf, int len);
int VerifyLen(char *buf);

Here is what I would like to receive:

//Server Project:
int Server_GetPacket(SOCKET sd);

// library with public and private types
//  private API (not exposed to my client)
int ReceiveAll(SOCKET sd, char *buf, int len);
int VerifyLen(char *buf);
//  public API (header file available for client)
int Client_SendCommand(int command);
int Client_GetData(int command, char *buf, int len);

Thanks for any help would be appreciated.

+5
source share
3 answers

"private" DLL (, , ), "" . , , , .

, , DLL. , , - .

+1

static int ReceiveAll(SOCKET sd, char *buf, int len);

.., /.

+5

DLL, (dllname.def), . , , DLL.

. MSDN .

I think you can also achieve similar functionality using the keyword __declspec(dllexport)for the functions you want to export.

0
source

All Articles