My previous post loaded a dll at run time.
This loads a dll at compile time.
fp 3.2.2
gcc 12
replace.pas
library replace;
uses
sysutils;
function SAR(s:pchar;find:pchar;replace:pchar):pchar;
begin
exit(pchar(stringreplace(ansistring(s),ansistring(find),ansistring(replace),[rfReplaceAll])));
end;
procedure show(s:pchar);
var
a:ansistring;
begin
a:=s;
writeln(a);
end;
procedure wait();
begin
readln;
end;
exports
show,SAR,wait;
end.
c test code
#include<string.h>
void wait();
void show(char*);
char * SAR(char*,char*,char*);
#define plenty 100
int main(){
char string[]="This is a C string.";
char temp[plenty];
char * result;
show(string);
result=SAR(string,"C","returned");
strcpy(temp, result);
show(temp);
result=SAR(temp,"returned","C language");
strcpy(temp, result);
show(temp);
result=SAR(temp,"string","string returned again");
strcpy(temp, result);
show(temp);
show("Press return to continue . . .");
wait();
}
You should make sure your c code has access to the dll.
Best way is to put the c code and dll together.
Example
gcc.exe "path to somename.c and replace.dll\somename.c" -o "path to somename.c and replace.dll \somename.exe" -l replace -L" path to somename.c and replace.dll" -static-libgcc
or
You can probably do this in your c ide/editor
Nobody has suggested a way to use variadic parameters in pascal (to fully use writeln in c), maybe it is not possible?