%SYN_CHARTOSTR

Convert C-style character pointer to alpha

WTSupported in traditional Synergy on Windows

 

USupported on UNIX
VSupported on OpenVMS
length = %SYN_CHARTOSTR(pointer, alpha)

or

xcall SYN_CHARTOSTR(pointer, alpha)

Return value

length

The length of the original null-terminated string, not counting the null. (n)

Arguments

pointer

The character pointer that points to the null-terminated string you want to convert. (D_ADDR)

alpha

Returned with the converted alpha string. (a)

Discussion

%SYN_CHARTOSTR converts a C-style character pointer (char *) to a Synergy DBL alpha type. This routine can be useful for dealing with C routines that are in external DLLs or linked into the runtime. If the C routine returns a pointer to a null-terminated string, this routine can be used to copy the contents to a Synergy alpha variable. The contents of the null-terminated buffer whose address is pointer are copied into alpha. The null termination is removed from the copy, and any remaining space in alpha is blank-filled. Length may be larger than the size of the buffer into which the string was copied, although %SYN_CHARTOSTR only copies up to the size of the buffer.

Examples

main strex
.align
stack record
    kernel32    ,D_ADDR                         ;Handle to kernel32.dll
    ptr         ,D_ADDR                         ;Pointer to environment
    curr        ,D_ADDR                         ;Pointer to current entry
    len         ,i4                             ;Length of an entry
    buf         ,a256                           ;Buffer for conversion

proc
    open(1,o,"TT:")
    kernel32 = %dll_open("kernel32")
;
; GetEnvironmentStrings returns a pointer to a block of memory containing
; the environment settings for the current process. This data is a series
; of null-terminated strings, with an extra null at the end.
;
    ptr = %dll_call(kernel32, DLL_TYPE_WINAPI, "GetEnvironmentStringsA")
    curr = ptr
    while (len = %syn_chartostr(curr, buf))             ;Zero length means the end
      begin
        writes(1, %atrim(buf))                          ;Display the entry
        curr += len + 1                                 ;Advance to next, skip null
      end
    xcall dll_call(kernel32, DLL_TYPE_WINAPI, "FreeEnvironmentStringsA", ptr)
    xcall dll_close(kernel32)
    stop
endmain