[fpc-pascal] Writing a DLL to be use in a VBA code
luciano de souza
luchyanus at gmail.com
Sat Jun 6 09:16:29 CEST 2015
Hello all,
At work, I need to create a Excel sheet containing certain more
complex functions. I tried to use only VBA, but I released I will more
productive if I could use a DLL writen in Pascal for the heavier code.
Let see this DLL:
library test;
{$mode objfpc}{$H+}
function concatenate(name: string): string; cdecl;
begin
result := 'Freepascal ' + name;
end;
function first(names: array of string):string; cdecl; // Warning:
cdecl'ared functions have no high parameter
begin
result := names[0];
end;
exports
concatenate;
first;
end.
The compiler also raised this error: "test.pas(10,1) Fatal: Internal
error 201003031".
I don't know what I am doing wrong. But actually, the reason of my
message started from another point.
Freepascal codes works with strings as usual. DLLs works with pchar. I
could have declared the functions as the following:
function concatenate(name: pchar): pchar; cdecl;
function first(names: array of pchar): pchar; cdecl;
In the body of the functions, I would treat the conversions from pchar
to string and from string to pchar again. But, when I used "cdecl", am
I making this conversion automatically? Is there a compilation switch
that allows me to write strings and the compiled code having correctly
treated the allocations and disallocation of strings?
Suppose this VBA code:
public declare function concatenate lib "test" (name as string) as string
Is this the correct way to write the called function in Freepascal?
function concatenate(name: string): string; cdecl;
begin
result := 'Freepascal ' + name;
end;
--
Luciano de Souza
More information about the fpc-pascal
mailing list