Re: Danger of using FillMem() on a string? Speed of Abs()?

From: J French (erewhon_at_nowhere.com)
Date: 01/12/04


Date: Mon, 12 Jan 2004 12:32:32 +0000 (UTC)

On Sun, 11 Jan 2004 23:26:22 -0800, Jamie
<jamie_5_not_valid_after_5@charter.net> wrote:

>a string can be used ether way for API calls, the difference is that you
>need to set the desired length of the string before passing it as a
>PChar to a API function that is going to populate it and reset the
> length to its true value after the API call so that the end of string
>marker will line up on the NULL charactor.. this is only important if
>you plan on possibly adding to the string after the API call other wise
> it will add to the end of the SetLength that you set it for before the
>API call.
> for example ..
>Var
> S :String;
>Begin
> SetLength(S, Max_path);
> SetLength(S, GetWindowsDirectory(S, Pchar(Max_Path)));

Actually there is a major typo in the above
... PChar( MAX_PATH ) ???

Nitpicking ... but it is a good example how saving Variables can
obscure functionality - Terse code does not run faster

> ...
> this works well because the GetWindowsDirectory is called and resolved
> before the values are placed on the stack for the SetLength.
> etc.....
>
>
>
>
>>
>> ISTR somewhere in the Delphi help about casting between strings and
>> mchars, it basically says that you can cast a string to a PChar if and
>> only if you intend to use it as a read only variable (e.g. in the
>> context of a WinAPI call), and of course, it's not valid outside the
>> scope of the cast.
>>
>> MH.
>



Relevant Pages

  • Re: szPname As String * MAXPNAMELEN (How to declare)
    ... I am using GlobalAlloc API to allocate memeory for structure "MIXERCONTROL" ... And then I used following API function to get the mixer control iformation. ... >> Public szShortName As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Structure Marshalling Question
    ... > bones C API. ... > The BYTE array returned by this API function is actually text. ... > I would be perfectly happy to get this as a String, StringBuilder, ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Danger of using FillMem() on a string? Speed of Abs()?
    ... yes your correct, sorry about that, the pChar should have been around ... >>a string can be used ether way for API calls, ... >> before the values are placed on the stack for the SetLength. ...
    (comp.lang.pascal.delphi.misc)
  • Re: PInvoke Marshalling....
    ... The wParam is a pointer to a API defined structure (containing a Low DWORD ... contents of the string builder. ... "DeviceHandle" and not indicative that it is a windows handle. ... public static extern int SNAPI_SetVersionBuffer(IntPtr DeviceHandle, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Find path to outlook.exe
    ... an API to get it may be a slight bit more reliable. ... "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _ ... Public Function fGetOutlookEXE() As String ... Dim RetVal As Long ...
    (microsoft.public.access.modulesdaovba)

Loading