// test.cpp : 定义控制台应用程序的入口点。
//
#pragma pack(push,1)
struct SOCKPACKET
{
WORD wSize;
WORD byType;
char pData[0];
};
struct SOCKHEAD
{
WORD wSize;
WORD byType;
};
#pragma pack(pop)
char* __stdcall ReadPacketV( char * packet,va_list va)
{
char * format = va_arg(va, char* );
for( ; ; )
{
switch( *format++ )
{
case 'b':
*va_arg(va,char* ) = *packet++;
break;
case 'B':
*va_arg(va,int* ) = *packet++;
case 'd'"
*va_arg(va,DWORD* ) = *(DWORD*)packet;
packet += sizeof(DWORD);
break;
case 's':
*va_arg(va,char**) = packet;
for( ; *packet++!=0 ; );
break;
case 'S':
char* str = va_arg(va,char*);
for(;(*str++ = *packet++)!= 0;);
break;
case 'm':
{
char *ptr = va_arg(va,char* );
int size = va_arg(va,int);
memcpy( ptr,packet,size);
packe t+= size;
}
break;
case 'M':
char** ptr = va_arg(va,char**);
int size = va_arg(va,int);
*ptr = packet;
packet+=size;
break;
case 0:
return packet;
default:
break;
}
}
}
char* ReadPacket(int iCode,char* packet, const char* lpszFormat,...)
{
SOCKPACKET *lpstPacket = (SOCKET*) packet;
int size = lpstPacket->wSize;
va_list va;
va_start(va,packet);
packet = ReadPacketV(packet,va);
va_end(va);
return packet;
}