0

I'm creating a DLL in Delphi that must have the following C++ structure.

DWORD Load(char* &Test);

So the test must be a reference parameter. I tried 'var' and 'out' in Deplhi, but I get an error in my C++ application that uses the DLL.

2
  • 2
    char* is zero terminated string? Who allocates the contents? Who frees it? What does your code look like? What is the error? Details please. Don't make us guess. It isn't nearly as much fun that way. Commented Aug 30, 2011 at 17:46
  • 1
    Oops. I just noticed that I assumed you wanted to ask what the correct translation of that function declaration is. You haven't actually asked anything, though. Please edit your post to include a question, not just a bunch of statements. Commented Aug 30, 2011 at 18:09

2 Answers 2

3

A literal translation of that code is this:

function Load(var Test: PAnsiChar): DWord; cdecl;

Notice the calling convention. If you're missing that, then Delphi places the first parameter in a register, but the C++ code expects it on the top of the stack.

Sign up to request clarification or add additional context in comments.

1 Comment

1. Did you use the proper calling convention? 2. Did you use PAnsiChar (as your Delphi may map PChar to PWideChar)? 3. Did you copy the text in the DLL to your own storage immediately after you obtained it? 4. If you wrote the DLL, try a better approach (fill a buffer provided by the user up to the length also provided by the user).
1

Like 'Rob Kennedy' stated, it must have 'cdecl'. I fixed the problem by using that. Here is the fixed code

function Load(out Test : PAsniChar) : Integer; cdecl ; export;
begin
  Test := 'Test String';
end;

Thanks for the help!

1 Comment

You should accept his answer (click on the more or less V-shaped symbol under the votes score, at the top left of each question).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.