📄 dllbase.h
字号:
/*****************************************************************************/
//File name: dllbase.h
//Author: Darkay Li
//Version: 1.0
//Date: 2004/11/5
//Description: 提供动态连接库的基本操作,可以屏蔽WIN32和UNIX的不一致。
//Others:
//Function List:
//Class List:
//History:
/*****************************************************************************/
#ifndef INCLUDED_DLLBASE
#define INCLUDED_DLLBASE
#if defined(HAS_PRAGMA_ONCE)
#pragma PRAGMA_ONCE_DECLARE
#endif
#ifdef WIN32
#include <Windows.h>
#define RTLD_LAZY 0
#else
#include <dlfcn.h>
#endif
namespace stk
{
class DllBase
{
public:
#ifdef WIN32
bool open(const char *dll, int flag = RTLD_LAZY)
{
m_handle = ::LoadLibrary(dll);
return m_handle != NULL;
}
bool close()
{
if(m_handle)
return ::FreeLibrary(m_handle) == TRUE;
else
return false;
}
void *getsym(const char *symbol)
{
if(m_handle)
return ::GetProcAddress(m_handle, symbol);
else
return NULL;
}
void geterror(std::string &strError)
{
DWORD error = ::GetLastError();
LPVOID buf = NULL;
BOOL ok = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &buf,
0,
NULL
);
if(!ok)
{
//try to load network error message library
HMODULE dll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
if(dll)
{
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
dll,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &buf,
0,
NULL
);
FreeLibrary(dll);
}
}
if(buf)
{
//format :"error code : description"
char temp[16];
sprintf(temp, "%d", error);
strError = temp;
strError += " : ";
strError += (LPCTSTR)buf;
//remove the "\n"--0x0D0A
strError[strError.size() - 2] = '\0';
LocalFree(buf);
}
}
#else
bool open(const char *dll, int flag = RTLD_LAZY)
{
m_handle = ::dlopen(dll, flag);
return m_handle != NULL;
}
bool close()
{
if(m_handle)
return dlclose(m_handle) == 0;
else
return false;
}
void *getsym(const char *symbol)
{
if(m_handle)
return ::dlsym(m_handle, symbol);
else
return NULL;
}
void geterror(std::string &strError)
{
strError = ::dlerror();
}
#endif
private:
#ifdef WIN32
HMODULE m_handle;
#else
void * m_handle;
#endif
};
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -