Wednesday, February 18, 2004

Unicode question

A couple of days ago I wrote a simple function and a part of it looked like this:


CString str;
str.Format(_T("this is only a test"));
int idx = str.Find('o');
if( idx >= 0 )
str = str.Left(idx);

The project have UNICODE defined so when today I reviewed this piece of code it looked wrong because the Find method as a character parameter that is not treated really as an unicode character. However it did compile well (and work too) under Visual C++ 6.

So when I got home I decided I need to understand why it works. I opened my Microsoft Visual C++ .NET 2003 wrote this little test console app and I generated the asm and the results (in debug configuration) are:

 




; 22   :     int idx = str.Find('o');

mov esi, esp
push 0
push 111 ; 0000006fH
lea ecx, DWORD PTR _str$[ebp]
call DWORD PTR __imp_?Find@?$CStringT@GV? (...)
cmp esi, esp
call __RTC_CheckEsp
mov DWORD PTR _idx$[ebp], eax
; 22   :     int idx = str.Find(_T('o'));

mov esi, esp
push 0
push 111 ; 0000006fH
lea ecx, DWORD PTR _str$[ebp]
call DWORD PTR __imp_?Find@?$CStringT@GV? (...)
cmp esi, esp
call __RTC_CheckEsp
mov DWORD PTR _idx$[ebp], eax

So both of them are compiled in the same manner. That's explain why it did compile successfully and why it works but I still doesn't understand why it didn't require the L (or TEXT or _T) macro.

Tuesday, February 17, 2004

MFC and taskbar

To make your application to not have a taskbar button, you need to have you main window owned by an invisible window or the main window should have the WS_EX_TOOLWINDOW style.

Friday, February 13, 2004

VARIANT_BOOL hint

When you are writing COM objects with support for OLE Automation types, you may have to deal with VARIANT_BOOL types. They are boolean values but unlink BOOL and bool its legal values are -1 (VARIANT_TRUE) and 0 (VARIANT_FALSE).

That means that if you call by mistake one of those methode with a bool or BOOL value, it will be implicitily converted to 0 and 1 values making it a perfectly legal call, but if you do have something like:

 

HRESULT foocall(VARIANT_BOOL boolParam)

{

    if( boolParam == VARIANT_TRUE )

        return S_OK;

    return S_FALSE;

}

 

Than you are in big trouble if you mismatch what you pass to the method. When you are dealing with VARIANT_BOOL types is always better to check for VARIANT_FALSE which is always 0 as for bool and BOOL types, so you should write the previous method like:

 

HRESULT foocall(VARIANT_BOOL boolParam)

{

    if( boolParam == VARIANT_FALSE )

        return S_FALSE;

    return S_OK;

}

 

Microsoft Win32 to Microsoft .NET Framework API Map

This link is something really useful for who is learning .net and have a tough win32 background.

 

Wednesday, February 11, 2004

The Ten Rules of Performance

From Paul Vick the 10 rules to work out perfomances problem:

http://www.panopticoncentral.net/PermaLink.aspx/eacfc5e0-42df-44b0-bb9a-94354b689b17

I like the 9th and 10th rule, they are so true.

Monday, February 09, 2004

Callbacks in C++

While reading Raymond Chen today I came across a technique to implement callback in c++. Having already implemented such things on my own, I'll give it a try and eventually update my code.

Thursday, February 05, 2004

Goggle's power

Don Box was having problems looking up SOAP 1.1 protocol specs.

A simple google query would have give him the needed help.