CString

See Also: Type Conversion Functions, String Functions, CStringLength, CStringSize

Purpose

The CString function translates a zero terminated C-string to a standard DataFlex string.

Return Type

String

Syntax

CString( {Var} )

Where:

Example

Procedure DoSomething

    string sFileName

    

    move (CString(sFileName)) to sFileName

End_Procedure

Notes

If a DataFlex program calls a DLL (to make a Windows API call, for example) and the function addressed returns a string, there are 2 possibilities: either the calling program (DataFlex) must pass a pointer to preserved space in memory at which the DLL writes the result, or the called program (the DLL function) returns a pointer to memory in which the value is stored.

See External_Function for more information on calling DLLs from DataFlex.

In languages like 'C' - used to create DLLs - string types are different than those in DataFlex. A string in such languages is an array of characters which is terminated with a 0 (zero) character to indicate the end of the string.

If your function call returns the data in the memory space of a DataFlex string variable, you must get rid of the bytes after the terminating zero.

The CString function translates a zero terminated C-style string to a standard DataFlex string.

Example

ZeroString 20 To sResult

Move (SomeAPIFunction (AddressOf (sResult)) To iRetval

If (iRetval) Begin

    Move (CString (sResult)) To sResult

End

Example

Define MAX_COMPUTERNAME_LENGTH For 15

 

External_Function WinAPI_GetComputerName "GetComputerNameA" Kernel32.Dll ;

    Pointer lpComputerName DWord nNameSize ;

        Returns Integer

 

Function GetComputerName Desktop Returns String

    String sComputerName

    Dword dwNameSize

    Integer iRetval

    

    ZeroString MAX_COMPUTERNAME_LENGTH To sComputerName

    Move MAX_COMPUTERNAME_LENGTH To dwNameSize

    

    Move (WinAPI_GetComputerName (AddressOf (sComputerName), AddressOf (dwNameSize))) To iRetval

    

    Function_Return (CString (sComputerName))

End_Function