String parameter problems for Unicode controls

Source: Internet
Author: User
Tags empty
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.