#include "StdAfx.h" #include "LanShareDll.h" namespace LanShareDll { HMODULE g_hLANShareDLL = NULL; DisConnectSession g_DisConnectSession = NULL; DelShareDirectoryW g_DelShareDirectoryW = NULL; DelShareDirectoryA g_DelShareDirectoryA = NULL; IsTheDirectorySharedW g_IsTheDirectorySharedW = NULL; IsTheDirectorySharedA g_IsTheDirectorySharedA = NULL; AccessShareDirectory g_AccessShareDirectory = NULL; AddShareDirectoryW g_AddShareDirectoryW = NULL; AddShareDirectoryA g_AddShareDirectoryA = NULL; SetNetShareSecurity g_SetNetShareSecurity = NULL; AddAccessRights g_AddAccessRights = NULL; BOOL LoadLANShareLibrary() { if (g_hLANShareDLL == NULL) g_hLANShareDLL = LoadLibrary(_T("LANShare.dll")); if (g_hLANShareDLL == NULL) { AfxMessageBox(_T("¼ÓÔØLANShareÄ£¿éʧ°Ü£¡")); return FALSE; } g_DisConnectSession = (DisConnectSession)::GetProcAddress(g_hLANShareDLL, "DisConnectSession"); g_DelShareDirectoryW = (DelShareDirectoryW)::GetProcAddress(g_hLANShareDLL, "DelShareDirectoryW"); g_DelShareDirectoryA = (DelShareDirectoryA)::GetProcAddress(g_hLANShareDLL, "DelShareDirectoryA"); g_IsTheDirectorySharedW = (IsTheDirectorySharedW)::GetProcAddress(g_hLANShareDLL, "IsTheDirectorySharedW"); g_IsTheDirectorySharedA = (IsTheDirectorySharedA)::GetProcAddress(g_hLANShareDLL, "IsTheDirectorySharedA"); g_AccessShareDirectory = (AccessShareDirectory)::GetProcAddress(g_hLANShareDLL, "AccessShareDirectory"); g_AddShareDirectoryW = (AddShareDirectoryW)::GetProcAddress(g_hLANShareDLL, "AddShareDirectoryW"); g_AddShareDirectoryA = (AddShareDirectoryA)::GetProcAddress(g_hLANShareDLL, "AddShareDirectoryA"); g_SetNetShareSecurity = (SetNetShareSecurity)::GetProcAddress(g_hLANShareDLL, "SetNetShareSecurity"); g_AddAccessRights = (AddAccessRights)::GetProcAddress(g_hLANShareDLL, "AddAccessRights"); return TRUE; } void FreeLANShareLibrary() { if (g_hLANShareDLL) { if ( !FreeLibrary(g_hLANShareDLL) ) { _tprintf_s(_T("ÊÍ·ÅLANShare.dllʧ°Ü,%d\n"), GetLastError()); } } g_hLANShareDLL = NULL; g_DisConnectSession = NULL; g_DelShareDirectoryW = NULL; g_DelShareDirectoryA = NULL; g_IsTheDirectorySharedW = NULL; g_IsTheDirectorySharedA = NULL; g_AccessShareDirectory = NULL; g_AddShareDirectoryW = NULL; g_AddShareDirectoryA = NULL; g_SetNetShareSecurity = NULL; g_AddAccessRights = NULL; } BOOL API_DisConnectSession( IN LPCTSTR lpHostAddr ) { if ( g_DisConnectSession ) return g_DisConnectSession(lpHostAddr); else _tprintf_s(_T("¼ÓÔØDisConnectSessionº¯Êýʧ°Ü\n")); return FALSE; } BOOL API_DelShareDirectory( IN LPCTSTR lpShareName ) { #ifdef UNICODE if ( g_DelShareDirectoryW ) return g_DelShareDirectoryW(lpShareName); #else if ( g_DelShareDirectoryA ) return g_DelShareDirectoryA(lpShareName); #endif else _tprintf_s(_T("¼ÓÔØDelShareDirectoryº¯Êýʧ°Ü\n")); return FALSE; } BOOL API_IsTheDirectoryShared(IN LPCTSTR lpDirectory, OUT LPTSTR lpShareName /* = NULL */, IN const INT& nBufLen /* = 0 */ ) { #ifdef UNICODE if ( g_IsTheDirectorySharedW ) return g_IsTheDirectorySharedW(lpDirectory, lpShareName, nBufLen); #else if ( g_IsTheDirectorySharedA ) return g_IsTheDirectorySharedA(lpDirectory, lpShareName, nBufLen); #endif else _tprintf_s(_T("¼ÓÔØIsTheDirectorySharedº¯Êýʧ°Ü\n")); return FALSE; } BOOL API_AccessShareDirectory(IN LPCTSTR lpUserName, IN LPCTSTR lpPasswd, IN LPCTSTR lpShareDirectory) { if ( g_AccessShareDirectory ) return g_AccessShareDirectory(lpUserName, lpPasswd, lpShareDirectory); else _tprintf_s(_T("¼ÓÔØAccessShareDirectoryº¯Êýʧ°Ü\n")); return FALSE; } BOOL API_AddShareDirectory(IN LPCTSTR lpDirectory, IN LPCTSTR lpShareName) { #ifdef UNICODE if ( g_AddShareDirectoryW ) return g_AddShareDirectoryW(lpDirectory, lpShareName); #else if ( g_AddShareDirectoryA ) return g_AddShareDirectoryA(lpDirectory, lpShareName); #endif else _tprintf_s(_T("¼ÓÔØAddShareDirectoryº¯Êýʧ°Ü\n")); return FALSE; } BOOL API_SetNetShareSecurity(IN LPCTSTR lpShareName, IN LPCTSTR lpUsser, IN const DWORD& dwPermissions /* = STANDARD_RIGHTS_ALL| SPECIFIC_RIGHTS_ALL */ ) { if ( g_SetNetShareSecurity ) return g_SetNetShareSecurity(lpShareName, lpUsser, dwPermissions); else _tprintf_s(_T("¼ÓÔØSetNetShareSecurityº¯Êýʧ°Ü\n")); return FALSE; } BOOL API_AddAccessRights(IN LPCTSTR lpszFileName, IN LPCTSTR lpszAccountName, IN const DWORD& dwAccessMask /* = STANDARD_RIGHTS_ALL| SPECIFIC_RIGHTS_ALL */ ) { if ( g_AddAccessRights ) return g_AddAccessRights(lpszFileName, lpszAccountName, dwAccessMask); else _tprintf_s(_T("¼ÓÔØAddAccessRightsº¯Êýʧ°Ü\n")); return FALSE; } };