Click here to Skip to main content
15,921,179 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include "stdafx.h"
#include <memory.h>
#include <windows.h>
#include <winsock2.h>
#include <iostream.h>
#include <lm.h>
#include <vector>
#include <string>
#include <memory.h>
using namespace std;
struct ClientInformation
{
	string sCliName;
	int iPlatId;
	int iMajor;
	int iType;
	int iMinor;
};

class cClient
{
private:
	DWORD dwLevel;
	DWORD dwPrefMaxLen;
	LPSERVER_INFO_101 pBuf;
	DWORD dwEntriesRead;
	DWORD dwTotalEntries;
	DWORD dwServerType;
	LPTSTR pszDomainName;
	NET_API_STATUS nStatus;
	WSADATA wsaData;
	DWORD dwResumeHandle;
	char cszBuf[200];
	SOCKET ClientSocket;
	int iTemp;
	string str;
public:
	cClient()
	{
		dwLevel = 101;
		dwPrefMaxLen = MAX_PREFERRED_LENGTH;
		pBuf = NULL;
		dwEntriesRead = 0;
		dwTotalEntries = 0;
		dwServerType = SV_TYPE_SERVER;
		pszDomainName = NULL;
		dwResumeHandle = 0;	
		
	}
	
	void FindDomainSystem()
	{	
		ClientInformation *StructObj;
		vector <ClientInformation> *myvec;
		WSAStartup(MAKEWORD(2,2), &wsaData);
		nStatus = NetServerEnum(NULL,dwLevel,(LPBYTE *) & pBuf,dwPrefMaxLen,
								&dwEntriesRead,&dwTotalEntries,dwServerType, 
								NULL, &dwResumeHandle);
		myvec = new vector <ClientInformation>();

		if(nStatus == NERR_Success)
		{
			cout<<"The NetServerEnumeration sucessfuly "<<"\n";
			cout<<"The total entires is "<<dwEntriesRead<<"\n\n";
			for(int i=1; i<= dwEntriesRead;i++)
			{
				
				memset(cszBuf,0,sizeof(cszBuf));
                                myvec = new vector <ClientInformation>();
				sprintf( cszBuf, "%S", pBuf->sv101_name );
				cout<<"\nThe server name "<<cszBuf<<"\n";
				StructObj->sCliName.erase();
				StructObj->sCliName.append(cszBuf);
				cout<<"The Platform id of the system is "<<pBuf->sv101_platform_id<<"\n";
				StructObj->iPlatId = pBuf->sv101_platform_id; 
				cout<<"The type of system running is "<<pBuf->sv101_type<<"\n";
				StructObj->iType = pBuf->sv101_type;
				cout<<"The major version of the system is "<<pBuf->sv101_version_major<<"\n";
				StructObj->iMajor = pBuf->sv101_version_major;
				cout<<"The minor version of the system is "<<pBuf->sv101_version_minor<<"\n";
				StructObj->iMinor = pBuf->sv101_version_minor;		
				send(ClientSocket,(char*)&StructObj,sizeof(StructObj),0);
				myvec->push_back(*StructObj);
				pBuf++;
			}
		}
		else
		{
			cout<<"\nThe Net Enumeration producing Error\n";
		}
		cout<<"\n\n\n\nThe vector data\n";
		display(myvec);
		
	}
	void display(vector <ClientInformation> *my)
	{
		BYTE *pData = NULL;
		if(my)
		{
			int i = my->size();
			if(i)
			{
				pData = new BYTE(i*sizeof(ClientInformation));
				ClientInformation *psData = (ClientInformation*)pData;
				for(int i1=0;i1<i;i++)
				{
					memcpy_s(psData[i1],sizeof(ClientInformation),&my->at(i1),sizeof(ClientInformation));  //prodcing error in that place.. what i want to do now...
				}
			}

			//int icount = my
		}
		
	}


};
int main(int argc, char* argv[])
{
	
	cClient o;
	o.FindDomainSystem();
	return 0;
}


sir.. this is my program that get the system information that are available under the domain..

problem is i can't able to send that data over the socket
..
for that purpose i done BYTE operation.

but the memcpy_s();
it gives error..

please help me
Posted
Updated 27-Jul-11 22:31pm
v3

Try this:
memcpy_s(psData+i1,sizeof(ClientInformation),&my->at(i1),sizeof(ClientInformation));

or
memcpy_s(&psData[i1],sizeof(ClientInformation),&my->at(i1),sizeof(ClientInformation));

or
memcpy(psData+i1,&my->at(i1),sizeof(ClientInformation));

Regards.
 
Share this answer
 
but the memcpy_s(); it gives error..
Well we cannot guess what the error is, perhaps you could clarify.
Also I am not sure about using memcpy to copy a structure that contains a string
 
Share this answer
 
Comments
Dhanasundhari 28-Jul-11 5:36am    
The error is the memecpy_s() is a undeclared varriable..
i use both the header files (string.h and memory.h)
but it producing the same error. There is an any other method to serialize the data ..
Richard MacCutchan 28-Jul-11 5:53am    
memecpy_s does not exist, are you sure of your spelling, or are you using a downlevel version of the compiler?
Show the exact line where you get this error; also clarify whether this is a compiler or linker message.
Shouldn't it be
C++
new BYTE[...];
rather than
C++
new BYTE(...);
i.e allocation of an array of BYTES instead of a single initialized BYTE ?
 
Share this answer
 
Comments
Dhanasundhari 28-Jul-11 5:37am    
ok. sir . i will do that.

there is an any way to send the vector via socket communication in c++
YvesDaoust 28-Jul-11 5:43am    
What do yo mean ? Just send the bytes...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900