Forum > Beginners

How to make a Lazarus built dll portable


I have made a dll that interfaces with an application (for which i don't have source access). It works perfectly on my computer but fails to work when used on other machines. The other machines processor manufacturer and Operating system matches mine. I think it's important to note that when observed with Api Monitor i can see that the host program correctly calls the exported functions from the dll but the dll gives incorrect return values. The problem also persists if i install FreePascal, Lazarus and internettools on the other machine. I even tried building the dll on the other machine with the same results. I would be happy to receive some kind of advice on how to proceed. Thank you! :)

The code is:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---library PascalLookup; {$mode objfpc}{$H+} {$R *.res} uses  Classes,  fileutil,  Windows,  sysutils,  xquery, PUCU, internetaccess, w32internetaccess;  //Ez keresi meg az Application Data mappátfunction GetAppdataFolder: string;begin     Result := GetEnvironmentVariable('APPDATA');end;//Ennek nincs szerepe a jelenlegi Implementációbanfunction Initialize(): Longint; cdecl;begin     Initialize := 0;end;//Ennek nincs szerepe a jelenlegi Implementációbanfunction DeInitialize(): Longint; cdecl;begin     DeInitialize := 0;end; //Ennek nincs szerepe a jelenlegi JAWS Implementációbanfunction GetInterfaceSchema(var dwSchema: LongWord): Longint; cdecl;begin     dwSchema := 12;     GetInterfaceSchema := 12;end; var  namelist, filename, rulefolder: WideString;  filestring: string;  firstloop: Boolean;  filenamelist: TStringList;  rulefile: TextFile;  namepos, i: Integer;//Ez írja ki a modulok nevétfunction GetFriendlyName(lpszOut: LPWSTR; var dwSize: LongWord): LongWord; cdecl;begin     rulefolder := 'C:\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\'; //GetAppdataFolder()+'\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\';     filenamelist := TStringList.Create();     FindAllFiles(filenamelist, rulefolder, '*.rul', true);      firstloop := true;     i:=0;     while i < filenamelist.Count do     begin        filename := filenamelist[i];       if(firstloop = false) then          namelist := namelist+'|'       else          firstloop := false;       namelist := namelist+copy(filename, Length(rulefolder)+1, Length(filename)-Length(rulefolder)-4);       //Delete(namelist,Length(namelist)-2,3); //to remove the extension from the name       namelist := namelist+':';        filestring:= ReadFileToString(filename); //I SHOULD PROBABLY GO BACK TO USING READLN        //readln(rulefile, ruleline); //USE POS LIKE THIS: s:='note-book';                                     //x:=pos('book',s); {x will be 6}       namepos :=pos('FriendlyName=',filestring);       if namepos<>0 then //the line exists       begin            filestring:=copy(filestring,namepos+13,Length(filestring)-namepos-13); //get everything from the start of the Friendlyname value            SetCodePage(RawByteString(filestring), 1252, false);//So utf8 characters work            namelist := namelist + copy(filestring,1,pos(sLineBreak, filestring)-1); //add everything from the value to the next linebreak        end;       i:= i+1;     end;        filenamelist.Free();     namelist := 'hello:Hello|plswork:illwork|thxdud:noprob|thisistheplace:a'+filenamelist[1];     if dwSize >Length(namelist) then        strCopy(lpszOut,PWideChar(namelist))     else         begin              dwSize := Length(namelist)+1;              result := $802A0001         end;     result := 0;end; var description, descfilestring: string;  plsmukodj: PWideChar;  descpos: Integer;  //Ez írja ki a modul leírásátfunction Describe(const lpszRuleSet: LPCWSTR; lpszOut: LPWSTR; var dwSize: DWord): LongWord; cdecl;begin     rulefolder := GetAppdataFolder()+'\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\';     descfilestring:= ReadFileToString(rulefolder+lpszRuleSet+'.rul'); //I SHOULD PROBABLY GO BACK TO USING READLN      //USE POS LIKE THIS: s:='note-book';      //x:=pos('book',s); {x will be 6}     descpos :=pos('Description=',descfilestring);     if descpos<>0 then //the line exists     begin          descfilestring:=copy(descfilestring,descpos+12,Length(descfilestring)-descpos-12); //get everything from the start of the Description value          SetCodePage(RawByteString(descfilestring), 65001, false);//So utf8 characters work          description := copy(descfilestring,1,pos(sLineBreak, descfilestring)-1); //add everything from the value to the next linebreak     end;      SetCodePage(RawByteString(description), 1252, false);     if dwSize >Length(description) then        begin             strCopy(lpszOut,PWideChar(WideString(description)));             result := 0        end     else         begin              dwSize := Length(description)+1;              result := $802A0001         end;end; var  queryresult, querysource, fsi, infoalap: string;  engine: TXQueryEngine;   //Ez fut le amikor ténylegesen be kell töltenie a szöveget a modulnakfunction Invoke(const lpszRuleSet: LPCWSTR; const lpszIn: LPCWSTR; const lpszContext: LPCWSTR; dwOffset: LongWord; lcidAppLocale: LongWord; lpszOut: LPWSTR; var dwSize: LongWord; lpExtra: Pointer): LongWord; cdecl;begin     defaultInternetAccessClass := TW32InternetAccess;      querysource := ReadFileToString(GetAppdataFolder()+'\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\'+lpszRuleSet+'.qry');     SetCodePage(RawByteString(querysource), 1252, false);     fsi := ReadFileToString('c:\Program Files\Freedom Scientific\JAWS\2022\LookupModules\ResearchItLibrary.jri');     SetCodePage(RawByteString(fsi), 1252, false);     infoalap := ReadFileToString('c:\Program Files\Freedom Scientific\JAWS\2022\LookupModules\InfoalapResearchIt.jri');     SetCodePage(RawByteString(fsi), 1252, false);      engine := defaultQueryEngine();     //engine.StaticContext.baseURI := 'c:\"Program Files"\"Freedom Scientific"\JAWS\2022\LookupModules\';     engine.registerModule(engine.parseQuery(fsi)); //Regisztráljuk a modulokat     engine.registerModule(engine.parseQuery(infoalap));     engine.VariableChangelog.add('inputvar',lpszIn);//A keresési szót is regisztráljuk    inputvar néven     queryresult := engine.evaluateXQuery(WideString(querysource)).toXQuery(); //     SetCodePage(RawByteString(queryresult), 65001, false);      if dwSize >Length(queryresult)+1 then        begin             strCopy(lpszOut,PWideChar(WideString(queryresult)));             result := 0        end     else         begin              dwSize := Length(queryresult)+2;              result := $802A0001         end;end; exports  Initialize,  DeInitialize,  GetInterfaceSchema,  GetFriendlyName,  Describe,  Invoke;end.

You have GetEnvironmentVariable('APPDATA') and some hard-coded paths. Maybe they differ between the computers.
Write debug info into a log file to debug it.

Are the files on both systems using codepage 1252?

The path ends with "hun", shouldn't you use 1250 for Hungarian?

When it fails, what exactly fails?

You can try to debug the dll from within Lazarus by adding the application as a host in:
  Run - Run Parameters - Host application

It depends on the host application, but worth a try.

my windows 10 points to the ROAMING folder of the APPDATA when using that method to obtain the APPDATA path.

I don't have anything in my Roaming path, its all in the local..

But there is a Key for LOCALAPPDATA which does point to the local one, maybe you should try that instead.


[0] Message Index

Go to full version