윈도우즈에서 자주 사용하는 “공유” 기능과 관련된 함수들이다.
#include <LM.h> #pragma comment(lib, "Netapi32.lib") void show_share(const char* path) { wchar_t lpszServer[1024+1] = {0, }; ::mbstowcs(lpszServer, path, 1024); NET_API_STATUS res = 0; do { PSHARE_INFO_1 pShareInfo, p; DWORD entries_read = 0, total_entries = 0, resume = 0; res = ::NetShareEnum (lpszServer, 1, reinterpret_cast<LPBYTE*>(&pShareInfo), 0xFFFFFFFF, &entries_read, &total_entries, &resume); if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA) { p = pShareInfo; for (DWORD i=1; i <= entries_read; i++, p++) { wprintf(L"%s -- ", p->shi1_netname); switch (p->shi1_type) { case STYPE_DISKTREE: wprintf(L"Disk drive"); break; case STYPE_PRINTQ: wprintf(L"Print queue"); break; case STYPE_DEVICE: wprintf(L"Communication device"); break; case STYPE_IPC: wprintf(L"Interprocess communication (IPC)"); break; case STYPE_SPECIAL: wprintf(L"Special share"); break; case STYPE_TEMPORARY: wprintf(L"A temporary share"); break; default: wprintf(L"Unknown type"); break; } wprintf(L"\n", p->shi1_netname); } // Free the allocated buffer. ::NetApiBufferFree(pShareInfo); } else { wprintf(L"Error: %ld\n", res); } } while (res==ERROR_MORE_DATA); } ... show_share("\\\\BACKUP_SERVER");