Usage description
ServerAPI Tutorial in C Language
1 Usage
1.Load library
2.Get pointer to function, which can initialize library
3.Initialize library
4.Get pointer to function, which can send request and receive response
5.Get pointer to function, which can free response
6.Send request and receive response + free response
7.Get pointer to function, which can deinitialize library
8.Deinitialize library
9.Free library
1.1 Load library
HMODULE hMod = LoadLibrary(L"ServerApi.dll");
if (!hMod)
{
//error
}
Free library:
FreeLibrary(hMod);
1.2 Get pointer to function, which can initialize library
typedef int (*era_init_lib)();
era_init_lib init_lib = (era_init_lib)GetProcAddress(hMod,"era_init_lib");
if(!init_lib)
{
//error
}
1.3 Initialize library
int res = init_lib();
Return value:
ERA_SUCCESS 0
ERA_INVALID_ARGUMENT 1
ERA_NOT_INITIALIZED 3
1.4 Get pointer to function, which can deinitialize library
typedef void (*era_deinit_lib)();
era_deinit_lib deinit_lib = (era_deinit_lib)GetProcAddress(hMod,"era_deinit_lib");
if(!deinit_lib)
{
//error
}
1.5 Get pointer to function, which can send request and receive response
typedef int (*era_process_request)(const char* request, char** response);
era_process_request send_request = (era_process_request)GetProcAddress(hMod,"era_process_request");
if(!send_request)
{
//error
}
1.6 Get pointer to function, which can free response
typedef void (*era_free)(char* s);
era_free free_response = (era_free)GetProcAddress(hMod,"era_free");
if(!era_free free_response)
{
//error
}
1.7 Send request and receive response
std::string request;
char* szRes = NULL;
int res = send_request(request.c_str(),&szRes);
request.c_str() – JSON request, [in] const char*
&szRes – JSON response, [out] char** response
Return value:
ERA_SUCCESS 0
ERA_UNSATISFIED_DEPENDENCY 2
Free response:
free_response(szRes);
szRes – [in] const char*
1.8 Deinitialize library
deinit_lib();