Controls | issues
Problem with passing string arguments found when writing Unicode controls:
Problem Description:
OCX of Unicode, attribute parameter text, type: BSTR.
The source code of the Control (VC)
afx_msg void SetText (LPCTSTR lpsztext)
VB call 1:
Dim Strtest as String
strtest = Text1.Text ' Text1 text box is empty
If not IsNull (strtest) Then
Testocx2221.stringtest = Strtest
End If
Results:
Lpsztext is null in SetText.
VB Call 2:
Dim Strtest as String
Strtest = ""
If not IsNull (strtest) Then
Testocx2221.stringtest = Strtest
End If
Results:
The lpsztext in SetText is not NULL, and a valid pointer to the empty string is obtained.
So:
The above call 1 o'clock:
When a control's handler directly invokes CString = = or!=, there is a problem, because CString these two operators do not support null and can make an error. That is, an operation with a null pointer is invoked.
Well, take the insurance approach: add one more sentence:
If (lpsztext==null) lpsztext = _t ("");
Very strange:
I do not know why the two kinds of VB call will be different values. I don't understand.
As for why ANSI does not have a problem, it may be because VB calls the ANSI control, you need to do an internal conversion of the string (by Unicode to ANSI), and away from the possibility of a null pointer.