Null Pointer Crash with Blank Tab Caption

Summary

Id: 2767.1
Type: Bug Bug
Current Status: Open

Detail

7 Jun 2003 Open Stefan Triess

Project pTestTabs6, form frmTestTabs:

-------------------------------------Sub Form_Load()... Set c = .Tabs.Add("CONTENTS")...End Sub-------------------------------------

This Code results for the Project vbalDTab6, UserControl vbalDTabControl in

-------------------------------------Private Sub drawTabs(Optional ByVal lhDCTo As Long = 0)... If m_bIsNt Then DrawTextW lHDC, StrPtr(m_tTab(iC).sCaption), -1, tCalcR,DT_CALCRECT Or DT_LEFT Or DT_SINGLELINE Else DrawText lHDC, m_tTab(iC).sCaption, -1, tCalcR, DT_CALCRECTOr DT_LEFT Or DT_SINGLELINE End If...End Sub-------------------------------------

to StrPtr(m_tTab(iC).sCaption = 0 (means null, not a pointer to a nullstring!) Because of this the function DrawTextW() crashes the Application. So for a short workaround I changed the code as followed:

-------------------------------------Private Sub drawTabs(Optional ByVal lhDCTo As Long = 0)... If m_bIsNt Then Dim sp& sp = StrPtr(m_tTab(iC).sCaption) If sp Then DrawTextW lHDC, StrPtr(m_tTab(iC).sCaption), -1,tCalcR, DT_CALCRECT Or DT_LEFT Or DT_SINGLELINE Else DrawText lHDC, m_tTab(iC).sCaption, -1, tCalcR, DT_CALCRECT OrDT_LEFT Or DT_SINGLELINE End If...End Sub-------------------------------------

Maybe, in the case, it is especially required to set tCalcR to dedicated values, but it seems to work fine. The function DrawText() resp. DrawTextA() seems not to crash, but I couldn't test it under real conditions. Perhaps VB's UNICODE to ANSI conversion with ByVal corrects the problem.

For me this works fine.

Date of the tested software: 27/04/03

Environment: VS6.0 SP5, WinNT4.0/SP6a and WinXP/SP1a