https://bugs.freedesktop.org/show_bug.cgi?id=81123

--- Comment #1 from Anton Kochkov <anton.koch...@gmail.com> ---
See short note about StrPtr:

    StrPtr is used primarily to make efficient UNICODE API calls. In VB4, API
calls to a UNICODE function were made with the help of byte arrays:

       Declare Sub MyUnicodeCall Lib "MyUnicodeDll.Dll" _
          (pStr As Byte)

       Sub MakeCall(MyStr As String)
          Dim bTmp() As Byte
          bTmp = MyStr & vbNullChar
          MyUnicodeCall bTmp(0)
          MyStr = bTmp
          MyStr = Left$(MyStr, Len(MyStr - 1))
       End Sub

    Clearly, the amount of work to simply pass a NULL terminated UNICODE string
and return its value into the original string is totally unacceptable. By the
time correct handling of the terminating NULL character is included, No less
than 4 copies of the string are required.

    With StrPtr, this code reduces to:

       Declare Sub MyUnicodeCall Lib "MyUnicodeDll.Dll" _
          (ByVal pStr As Long)

       Sub MakeCall(MyStr As String)
          MyUnicodeCall StrPtr(MyStr)
       End Sub

    VarPtr/StrPtr/ObjPtr are all very, very fast, so the overhead to call a
UNICODE function is now actually lower than calling the corresponding ANSI
function because no conversion is required.

    StrPtr can also be used to optimize ANSI declare calls. Instead of passing
the same string variable multiple times to a declare function and incurring the
conversion overhead for each call, use the StrConv function once and StrPtr in
each call:

       Declare Sub MyAnsiCall Lib "MyAnsiDll.Dll" _
          (ByVal pStr As String)

       MyAnsiCall MyStr

    becomes:

       Declare Sub MyAnsiCall Lib "MyAnsiDll.Dll" _
          (ByVal pStr As Long)

       MyStr = StrConv(MyStr, vbFromUnicode)
       MyAnsiCall StrPtr(MyStr)
       MyStr = StrConv(MyStr, vbUnicode) ' Not always required

    StrPtr is also the only way to tell the different between an empty string
("") and a null string (vbNullString). StrPtr(vbNullString) returns 0, while
StrPtr("") is non-zero.

>From http://vb.mvps.org/tips/varptr.asp

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
Libreoffice-bugs@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to