accessing PChar

im passing a pointer (PChar) from delphi to the external function (assembled linked .obj). I can use it to read the string but can not modify.

Function MyFunc(szString:PChar):ByteBool;register;external;

Comments

  • : im passing a pointer (PChar) from delphi to the external function (assembled linked .obj). I can use it to read the string but can not modify.
    :
    : Function MyFunc(szString:PChar):ByteBool;register;external;
    :
    :
    I you use a string to hold the text and let the PChar point to that:
    [code]
    var
    s: string;
    begin
    s := 'MyText';
    MyFunc(PChar(s));
    end;
    [/code]

  • The pointer passes to the function but the problem is that it is only usefull to read from the string. When i write to it i get accessviolation. The First one of the following function works while the second one doesnt even if the pointer is the same.

    function ReadFirstCharofString(szStr:Pchar):char;register;external;

    function ChangeFirstChar(szStr:Pchar):ByteBool;register;external;


    ReadFirstCharofString proc
    push esi
    mov esi,eax
    mov al,[esi]
    pop esi
    ret

    ChangeFirstChar proc
    push esi
    mov esi,eax
    mov [esi],'a'
    pop esi
    ret

  • : The pointer passes to the function but the problem is that it is only usefull to read from the string. When i write to it i get accessviolation. The First one of the following function works while the second one doesnt even if the pointer is the same.
    :
    : function ReadFirstCharofString(szStr:Pchar):char;register;external;
    :
    : function ChangeFirstChar(szStr:Pchar):ByteBool;register;external;
    :
    :
    : ReadFirstCharofString proc
    : push esi
    : mov esi,eax
    : mov al,[esi]
    : pop esi
    : ret
    :
    : ChangeFirstChar proc
    : push esi
    : mov esi,eax
    : mov [esi],'a'
    : pop esi
    : ret
    :
    :
    Perhaps you should ask this at the assembly board, because this is not really a Delphi language problem but more an assembly problem.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories