I'm new to this forum and this is my first post. I'm having trouble using a dll function with an *int parameter. The function is declared in the dll as
int sendQuoGetInfDstn(char* nomed, int *rigd)
I have imported this into Delphi 11 using
const
QUODLL = 'PcQuoDllNoWrap.dll';
implementation
function sendQuoGetInfDstn(Name: PAnsiChar; Count: PInteger): integer; stdcall; external QUODLL;
This compiles fine.
My question is, how do i call this function from my delphi program? I have tried all sorts of things, but i get Access violation errors or program crash. For example i have made this wrapper
function TPCQuo.GetWorklistInfoTest(Name: String; Count: integer): integer;
begin
result := sendQuoGetInfDstn(PAnsiChar(Ansistring(Name)), @Count); {I have also tried PInteger(Count)}
end;
And i call the wrapper like this
procedure TForm1.Button4Click(Sender: TObject);
var
name: String;
count: integer;
begin
if QUO.GetWorklistInfoTest(name, count) <> 0 then
ShowMessage('No worklist available ')
else
ShowMessage('Worklist available ' name ' number of lines: ' count.ToString );
end;
So how would you guys call this function?
Thank you for every little piece of help you can provide.
CodePudding user response:
There are a few possible issues here:
- The function may be
cdecl
rather thanstdcall
. It's not possible to say for sure but you'd need to look more closely at the supplied header file. - The first argument
char *nomed
might be expecting a modifiable character array. Perhaps the function does attempt to modify the text, or perhaps the author made a mistake and should have writtenconst char *nomed
. With the information provided here we cannot tell. - The encoding of the text could be ANSI, or it could be some other 8-bit encoding such as UTF-8. With the information provided here we cannot tell what it is.
- The second argument,
int *rigd
, could be either a pointer to a single integer, or it could be a pointer to an array. With the information provided here we cannot tell.
In summary, the only potential mistake in your translation is item 1. But getting the arguments, types and calling convention correct is only the first step. You also need to know the semantics of how to call a function. My best guess is that the issues are in that area, which will require information that you have, but we do not.