In Delphi in my DLL do I have to allocate the return pchar of a function

后端 未结 3 508
长情又很酷
长情又很酷 2021-02-14 09:20

I have a DLL in which I have a function that returns a pchar. (as to avoid having to use borlndmm) What I was doing originally was casting a string as a pchar and returning that

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 09:57

    When you return a string as PChar from function the string is held in stack, which is why it's sometimes corrupted. I use process heap memory for returning strings, or pointer to global buffer array of chars.

    Also you can use built-in assembler and do this:

    Function GetNameStr : PChar;
    Asm
      Call   @OverText
      DB     'Some text',0
    @OverText:
      Pop    EAX
    End;
    

提交回复
热议问题