MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / VarToBinary

Function VarToBinary

sourcecommon/utils.cpp:1051–1134  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1049}
1050//---------------------------------------------------------------------------
1051int VarToBinary(Variant v, BYTE * buf, int size)
1052{
1053 int RetVal = 0;
1054 try
1055 {
1056 if( v.IsArray() )
1057 {
1058 int n = v.ArrayHighBound();
1059 for(int j = v.ArrayLowBound(); j<=n; j++)
1060 {
1061 RetVal += VarToBinary(v.GetElement(j), buf+RetVal, size-RetVal);
1062 if( RetVal >= size ) return RetVal;
1063 }
1064 }
1065 else
1066 {
1067 switch( v.Type() )
1068 {
1069 //case varEmpty 0x0000 The variant is Unassigned.
1070 //case varNull 0x0001 The variant is Null.
1071 case varSmallint: // 0x0002 16-bit signed integer (type short int)
1072 *(short int *)(buf+RetVal) = (short int)v;
1073 RetVal += sizeof(short int);
1074 break;
1075 case varInteger: // 0x0003 32-bit signed integer (type int).
1076 *(int *)(buf+RetVal) = (int)v;
1077 RetVal += sizeof(int);
1078 break;
1079 case varSingle: // 0x0004 Single-precision floating-point value (type float)
1080 *(float *)(buf+RetVal) = (float)v;
1081 RetVal += sizeof(float);
1082 break;
1083 case varDouble: // 0x0005 Double-precision floating-point value (type double).
1084 *(double *)(buf+RetVal) = (double)v;
1085 RetVal += sizeof(double);
1086 break;
1087 case varCurrency: // 0x0006 Currency floating-point value (type Currency).
1088 *(Currency *)(buf+RetVal) = (Currency)(double)v;
1089 RetVal += sizeof(Currency);
1090 break;
1091 case varDate: // 0x0007 Date and time value (type TDateTime).
1092 *(TDateTime *)(buf+RetVal) = (TDateTime)(double)v;
1093 RetVal += sizeof(TDateTime);
1094 break;
1095 case varOleStr: // 0x0008 Reference to a dynamically allocated Unicode string.
1096 {
1097 AnsiString s = v;
1098 lstrcpy(buf+RetVal, s.c_str());
1099 RetVal += lstrlen(s.c_str());
1100 }
1101 break;
1102 //case varDispatch 0x0009 Reference to an OLE automation object (an IDispatch interface pointer).
1103 case varError: // 0x000A Operating system error code.
1104 *(int *)(buf+RetVal) = (int)v;
1105 RetVal += sizeof(int);
1106 break;
1107 case varBoolean: // 0x000B 16-bit boolean (type WordBool).
1108 *(WordBool *)(buf+RetVal) = (WordBool)v;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected