函数参考


_WinAPI_CreateString

Copies a specified string to the newly allocated memory block and returns its pointer.

#Include <WinAPIEx.au3>
_WinAPI_CreateString ( $sString [, $pString [, $iLength [, $fUnicode [, $fAbort]]]] )

参数

$sString The source string to be copied.
$pString [可选参数] A pointer to a string that to be replaced by a new string. If this parameter is a valid string pointer,
the memory will be reallocated for a new string. However, a new memory is allocated at a different
location. Therefore, you should always use a pointer that returns this function. If this parameter is
0, omitted, or an invalid string pointer, the function just allocates a new memory.
$iLength [可选参数] The required buffer length, in TCHARs, without null-terminating character. If this parameter is (-1),
the buffer length will be equal to the length of the source string. If $iLength is less than
a source string, the string will be truncated to the specified length.
$fUnicode [可选参数] Specifies whether a string is Unicode or ASCII code of a character, valid values:
TRUE - Unicode. (Default)
FALSE - ASCII.
$fAbort [可选参数] Specifies whether to exit the script if not enough memory, valid values:
TRUE - Displaying an error message and exit the script with code 1. (Default)
FALSE - Continue the script and return an error.

返回值

注意/说明

When a string is no longer needed, you must destroy it by calling the _WinAPI_FreeMemory() function.

相关

详情参考

None

示例/演示


#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $WM_MYMESSAGE = _WinAPI_RegisterWindowMessage('MyMessage')

Global $hForm, $Msg, $Button, $Input, $pString

$hForm = GUICreate('MyGUI', 400, 93)
$Input = GUICtrlCreateInput('', 20, 20, 360, 20)
$Button = GUICtrlCreateButton('Send', 165, 59, 70, 23)
GUIRegisterMsg($WM_MYMESSAGE, 'WM_MYMESSAGE')
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            ExitLoop
        Case $Button
            $pString = _WinAPI_CreateString(GUICtrlRead($Input))
            _WinAPI_SetMessageExtraInfo($pString)
            _SendMessage($hForm, $WM_MYMESSAGE, 1, 255)
            _WinAPI_FreeMemory($pString)
    EndSwitch
WEnd

Func WM_MYMESSAGE($hWnd, $iMsg, $wParam, $lParam)

    Local $pString = _WinAPI_GetMessageExtraInfo()

    If _WinAPI_IsMemory($pString) Then
        ConsoleWrite('WM_MYMESSAGE | WP = ' & Number($wParam) & ' | LP = ' & Number($lParam) & ' | EXTRA = "' & _WinAPI_GetString($pString) & '"' & @CR)
    EndIf
EndFunc   ;==>WM_MYMESSAGE