1

I got following errors when tried to calling .dll (made from delphi) function from unity3d C# code.

Here is pictures,

enter image description here

and errors says,

enter image description here

and .dll codes are,

enter image description here

So why error occurs and how to solve?

Thanks a lot!

1 Answer 1

6

Where you write

error = GetRequestResult(code);

you need to write

error = GetRequestResult(out code);

which is precisely what the second error message states.


Looking at your code, returning a PChar from the Delphi DLL the way that you do is not compatible with your P/invokes. The P/invoke marshaller is assuming that your return values were allocated with CoTaskMemAlloc and will call CoTaskMemFree on the pointer that you return. That's going to lead to some problems somewhere down the line. I think you'll need to tackle that issue at some point but since it's not the subject of this question, I won't attempt to solve the problem here.

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

4 Comments

and I don't understand well about your PChar....comments. So you mean I should not use just 'string' for 'PChar'? Isn't there a easy way to solve this communication problem, like change PChar to another type compatible with c#'s string?
The easiest thing to do is to use WideString on the Delphi side and [MarshalAs(UnmanagedType.BSTR)] on the C# side. But that doesn't work for return values since Delphi has rather unusual semantics for return values (see stackoverflow.com/questions/9349530/…). So I'd convert the string return values into out or ref parameters.
In fact I already covered this issue in some detail in your previous question! stackoverflow.com/questions/11175534/…
Hi, Do you have MS messanger ID or Skype ID?

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.