0

I got following problem:

I'm loading a function of a C-DLL in my Lazarus project like

@dpstate_callCustomfunction:= GetProcAddress(mConnectorLibrary, 'dpstate_callCustomfunction');  

this function got different implementations with different variables in the C-DLL, so I have to declare it more than 1 time in the Lazarus project. I tried it like:

 var dpstate_callCustomfunction: function(plugin, method, paramName: string; customfunctionCallbackFunction: string; id: PChar): integer; stdcall; overload; override;
 var dpstate_callCustomfunction: function(plugin, method, paramName: string; resultParam: PChar): integer; stdcall; reintroduce; overload;

But the compiler tells me following Errors: "Error: Procedure directive "OVERRIDE" not allowed in procvar declaration" "Error: Procedure directive "OVERLOAD" not allowed in procvar declaration"

What am I doing wrong? =/ If I remove the "var" it compiles, but I think I need the "var" or am I wrong?

2
  • 1
    Override is for methods. Could you not sidestep this whole issue by not using the same name for both on the Pascal side? Commented Feb 13, 2013 at 16:49
  • 4
    The function you're importing does not have different implementations with different arguments. DLLs do not support overloading. Each exported name refers to exactly one function in the DLL. If the DLL exports multiple functions, then they each use a distinct name, and there's no reason you shouldn't use those distinct names in your Delphi code, too. Commented Feb 13, 2013 at 17:09

1 Answer 1

4

Since you are declaring variables, they must have different names. Unlike functions, procedures and methods which can overload the same name.

So, solve your problem by choosing different names for your two variables.

And also remove everything after the stdcall in your two variable declarations. Those keywords only apply to procedures and methods, and not to procedural variables.

You have to use variables if you are going to link explicitly using GetProcAddress. You need a variable to hold the function pointer returned by GetProcAddress. If you linked implicitly using the external keyword, then you would not have a variable. And then you could declare functions overloaded with the same name.

I must admit that I am surprised that you chose the same name for these variables. They must have different names in the C code, and they must be exported from the DLL with different names. I hope you aren't trying to call the same function with different parameter lists. That certainly will not work.

The other problem that I can see you will have is that your string parameters cannot possibly match the parameters used in the C library. You'll need to use PChar I suspect. But that's really the topic for a different question.

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

Comments

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.