我正在做一个项目,我需要创建一个 API。我正在使用套接字在服务器(我的应用程序)和客户端(使用我的 API 的其他应用程序)之间进行通信。
这个项目是 c 而不是 C++
我来自 linux 背景,这是我第一个使用 Windows、Visual Studio 2008 和 dll 库的项目。
我在客户端和服务器之间进行了通信,但我有一些在两个项目中重复。我想创建一个库(可能是一个 dll 文件),这两个项目都可以链接到,所以我不必维护额外的代码。
我还必须创建包含我需要为我的客户提供的 API 的库。在我想要公开的 API 函数中,是对这些“重复代码”的辅助函数的调用,我不想将这些函数公开给我的客户端,但我确实希望我的服务器能够使用这些函数。我怎样才能做到这一点?
我将尝试用一个例子来澄清。这就是我开始的。
服务器项目:
int Server_GetPacket(SOCKET sd);
int ReceiveAll(SOCKET sd, char *buf, int len);
int VerifyLen(char *buf);
客户项目:
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);
这就是我想要的结果:
//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);
感谢任何帮助将不胜感激。