#ifndef NIM_SDK_HELPER_H_
#define NIM_SDK_HELPER_H_

#ifdef WIN32
#include<Windows.h>
#else
#	include <dlfcn.h>
#	include <sys/stat.h> /* stat() */
#include <errno.h>
#endif

#ifdef NULL
#define fcx_null    NULL /**< Null pointer */
#else
#define fcx_null    0  /**< Null pointer */
#endif

static const char* kSdkNIMDll = "nim.dll";

static void* instance_nim_ = fcx_null;  

#define nim_sdk_get_function(function_ptr) \
		((function_ptr)nim_get_function(#function_ptr))

 int nim_sdk_load(const char* dir_path)
{
	
#ifdef WIN32
	instance_nim_ = LoadLibraryA(dir_path);
#else 
    extern int errno;
	instance_nim_=dlopen(dir_path,RTLD_NOW);
    printf("errno->%d\n",errno);
#endif
	if (instance_nim_ == fcx_null)
		return 0;
	else
		return 1;
}

 int nim_sdk_unload()
 {
	 if (instance_nim_)
	 {
#ifdef WIN32
		 FreeLibrary(instance_nim_);
#else
		 dlclose(instance_nim_);
#endif
		 instance_nim_ = fcx_null;
		 return 1;
	 }
	 else
		 return 0;
 }

 void* nim_get_function(char* function_name)
{
	void* function_ptr =fcx_null;
#ifdef WIN32
    function_ptr=GetProcAddress(instance_nim_, function_name);
#else
    function_ptr=(void*)dlsym(instance_nim_,function_name);
#endif
	return function_ptr;
}

#endif
