[ mvlado @ 18.05.2003. 19:01 ] @
Ovaj kod izlista u jednom texbox-u UserName i IP broj svih korsinika koji su logovani na taj racunar. Potrebno mi je da se od ovog koda napravi dll fajl, kako bi mogao da ga koristim u VB, sa jednom funkciom koja bi se zvala npr. GetAllUsers (UserNo, Users) i koja bi vracala dva parametra, 1) Broj korisnika 2) Pokazivac na Niz recorda u obliku UserName as String Ip as String Pogledati ovaj text: Handling VB strings (as part of an array of UDT) http://www.codeguru.com/dll/vbString.shtml Ako neko ima bolje resenje neka uradi kako misli da treba pa naka detaljno opise resenje. Nebi bilo lose da neko malo detaljnije prokomentarise ovaj kod. Kompletan projekat se moze skinuti sa ove adrese: www.codeguru.com/network/IPAddress.zip Kod: 1) Include winsock2.h 2) In the Menu, go to Project-->Settings and in the Link tab, you can see a text box named Object/Library Modules. In that, add ws2_32.lib mpr.lib to the existing entries there. Those 2 libraries have to be added for this code snippet to compile without any linker errors. CString strTemp; struct hostent *host; struct in_addr *ptr; // To retrieve the IP Address DWORD dwScope = RESOURCE_CONTEXT; NETRESOURCE *NetResource = NULL; HANDLE hEnum; WNetOpenEnum( dwScope, NULL, NULL, NULL, &hEnum ); WSADATA wsaData; WSAStartup(MAKEWORD(1,1),&wsaData); if ( hEnum ) { DWORD Count = 0xFFFFFFFF; DWORD BufferSize = 2048; LPVOID Buffer = new char[2048]; WNetEnumResource( hEnum, &Count, Buffer, &BufferSize ); NetResource = (NETRESOURCE*)Buffer; char szHostName[200]; for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ ) { if ( NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY ) { if ( NetResource->lpRemoteName ) { CString strFullName = NetResource->lpRemoteName; if ( 0 == strFullName.Left(2).Compare("\\\\") ) strFullName = strFullName.Right(strFullName.GetLength()-2); gethostname( szHostName, strlen( szHostName ) ); host = gethostbyname(strFullName); if(host == NULL) continue; ptr = (struct in_addr *) host->h_addr_list[0]; // Eg. 211.40.35.76 split up like this. int a = ptr->S_un.S_un_b.s_b1; // 211 int b = ptr->S_un.S_un_b.s_b2; // 40 int c = ptr->S_un.S_un_b.s_b3; // 35 int d = ptr->S_un.S_un_b.s_b4; // 76 strTemp.Format("%s --> %d.%d.%d.%d",strFullName,a,b,c,d); AfxMessageBox(strTemp); } } } delete Buffer; WNetCloseEnum( hEnum ); } WSACleanup(); // End of Code |