The comments above are correct. Network material should not run in the user interface thread. BUT, if you do not want a thread, I believe that you want to list all open connections in order to find out if your resource is connected. Try WNetOpenEnum, for example:
#define _WIN32_WINNT 0x0500 #include <windows.h> #include <Winnetwk.h> #include <stdio.h> #pragma comment(lib,"Mpr.lib") VOID main(){ HANDLE hEnum = (HANDLE)0; DWORD dwError = WNetOpenEnum(RESOURCE_CONNECTED,RESOURCETYPE_DISK,0,NULL,&hEnum); if (dwError == NO_ERROR){ DWORD dwCount = -1; CHAR szBuff[1000]; ZeroMemory(szBuff,sizeof(szBuff)); DWORD dwSize = sizeof(szBuff); dwError = WNetEnumResource(hEnum,&dwCount,szBuff,&dwSize); if (dwError == NO_ERROR){ NETRESOURCE *pnr = (NETRESOURCE*)szBuff; for (DWORD d = 0; d < dwCount; d++){ if (pnr[d].lpRemoteName){ printf("%s\n",pnr[d].lpRemoteName); } } } WNetCloseEnum(hEnum); }else{ printf("Failed: %u\n",dwError); } }
This is a bit hacky, because I assume that all connections fit in 1000 bytes. You can read about the WNetOpenEnum function here too:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa385478%28v=vs.85%29.aspx
source share