Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Monday, February 20, 2006

stack size in VC++ program

The executable generated "Stack overflow" runtime error. At last it is fixed by changing
Configuration Properties->Linker->System
Stack Reserve Size = 8388608
Robert said that STL requires larger stack size.
Stupid OS. Why not grow stack at runtime.

Friday, February 17, 2006

the BOM in text file

I have a text file in resource which contained BOM, I tried some means to remove the BOM by copy to and back, replace with another file, but the one in clearcase always keeps the BOM. At last I have to remove it by skipping the first two bytes.
char* pdata = reinterpret_cast(lpData);
if( 0xff == pdata[0] && 0xFE == pdata[1] ) //skip BOM
{
pstart = pstart + 2/sizeof(TemplateType);
}

Thursday, February 16, 2006

_variant_t does not compare VT_DATE via == operator

VC80 does not compare VT_DATE via == operator in a good manner.
I expect the following to work, but it does not either.
double time_dif = abs(TimeStamp.date- xml_time.date);
bool time_ok = false;
if(time_dif <= (std::numeric_limits::min)())
time_ok = true;
at last I compare time_dif with 0.00000000001

Saturday, February 11, 2006

Must be careful with characterset of ADODB.Stream

_StreamPtr spStreamIn ; //stream from the definition file
(spStreamIn.CreateInstance (__uuidof(Stream)));
(spStreamIn->Open (vtMissing, adModeUnknown, adOpenStreamUnspecified, "", ""));
spStreamIn->Charset = _T("UTF-8");// _T("Unicode");
hr = spStreamIn->LoadFromFile(_T("c:\\users.txt"));
spStreamIn->Position =0;
_bstr_t input_xml = spStreamIn->ReadText(adReadAll);

binary to string in SQLServer

convert 0x1234 to "1234"
CREATE FUNCTION [dbo].[hexdecimal] (@binvalue varbinary(255))
RETURNS varchar(255) AS
BEGIN

DECLARE @hexvalue varchar(255)
DECLARE @charvalue varchar(255)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH(@binvalue)
SELECT @hexstring = '0123456789abcdef'
WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint int
DECLARE @secondint int
SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
SELECT @firstint = FLOOR(@tempint/16)
SELECT @secondint = @tempint - (@firstint*16)
SELECT @charvalue = @charvalue +
SUBSTRING(@hexstring, @firstint+1, 1) +
SUBSTRING(@hexstring, @secondint+1, 1)
SELECT @i = @i + 1

END
SELECT @hexvalue = substring(@charvalue,3, len(@charvalue)-2)
RETURN @hexvalue

END

--There are undocumented procedures: xp_varbintohexstr and master.dbo.fn_varbintohexstr

OT today

I work OT today, and I can't sign in msn spaces.

Friday, February 10, 2006

command to restart computer

shutdown -r -c "Rebooting for latest updates." -f -t 5