This patch adds 'loadwithalteredsearchpath' support to the SVN rev 1045 sources.

diff -ur 1045/Source/uPSC_dll.pas 1045a/Source/uPSC_dll.pas
--- 1045/Source/uPSC_dll.pas	Fri Jan 14 10:52:59 2005
+++ 1045a/Source/uPSC_dll.pas	Sun Sep 16 01:36:36 2007
@@ -40,12 +40,13 @@
 function DllExternalProc(Sender: TPSPascalCompiler; Decl: TPSParametersDecl; const Name, FExternal: string): TPSRegProc;
 var
   FuncName,
-  FuncCC, s: string;
+  FuncCC, s, s2: string;
   CC: TDllCallingConvention;
-  DelayLoad: Boolean;
+  DelayLoad, LoadWithAlteredSearchPath: Boolean;
 
 begin
   DelayLoad := False;
+  LoadWithAlteredSearchPath := False;
   FuncCC := FExternal;
   if (pos('@', FuncCC) = 0) then
   begin
@@ -63,15 +64,28 @@
     begin
       s := Copy(FuncCC, pos(' ', Funccc)+1, MaxInt);
       FuncCC := FastUpperCase(Copy(FuncCC, 1, pos(' ', FuncCC)-1));
-      Delete(FuncCC, pos(' ', Funccc), MaxInt);
-      if FastUppercase(s) = 'DELAYLOAD' then
-        DelayLoad := True
-      else
-      begin
-        Sender.MakeError('', ecCustomError, 'Invalid External');
-        Result := nil;
-        exit;
-      end;
+      repeat
+        if pos(' ', s) > 0 then begin
+          s2 := Copy(s, 1, pos(' ', s)-1);
+          delete(s, 1, pos(' ', s));
+        end else begin
+          s2 := s;
+          s := '';
+        end;
+        if FastUppercase(s2) = 'DELAYLOAD' then
+          DelayLoad := True
+        {$IFNDEF LINUX}
+        else
+        if FastUppercase(s2) = 'LOADWITHALTEREDSEARCHPATH' then
+          LoadWithAlteredSearchPath := True
+        {$ENDIF}
+        else
+        begin
+          Sender.MakeError('', ecCustomError, 'Invalid External');
+          Result := nil;
+          exit;
+        end;
+      until s = '';
     end else
       FuncCC := FastUpperCase(FuncCC);
     if FuncCC = 'STDCALL' then cc := ClStdCall else
@@ -89,7 +103,7 @@
     FuncCC := '';
     cc := DefaultCC;
   end;
-  FuncName := 'dll:'+FuncName+char(cc)+char(bytebool(DelayLoad)) + declToBits(Decl);
+  FuncName := 'dll:'+FuncName+char(cc)+char(bytebool(DelayLoad))+char(bytebool(LoadWithAlteredSearchPath)) + declToBits(Decl);
   Result := TPSRegProc.Create;
   Result.ImportDecl := FuncName;
   Result.Decl.Assign(Decl);
diff -ur 1045/Source/uPSR_dll.pas 1045a/Source/uPSR_dll.pas
--- 1045/Source/uPSR_dll.pas	Sat Jan 15 17:29:32 2005
+++ 1045a/Source/uPSR_dll.pas	Sun Sep 16 01:36:36 2007
@@ -24,7 +24,7 @@
 {
 p^.Ext1 contains the pointer to the Proc function
 p^.ExportDecl:
-  'dll:'+DllName+#0+FunctionName+#0+chr(Cc)+Chr(DelayLoad)+VarParams
+  'dll:'+DllName+#0+FunctionName+#0+chr(Cc)+Chr(DelayLoad)+Chr(AlternateSearchPath)+VarParams
 }
 
 type
@@ -83,7 +83,7 @@
 
 function LoadDll(Caller: TPSExec; P: TPSExternalProcRec): Boolean;
 var
-  s, s2: string;
+  s, s2, s3: string;
   h, i: Longint;
   ph: PLoadedDll;
   {$IFDEF LINUX}
@@ -91,12 +91,16 @@
   {$ELSE}
   dllhandle: THandle;
   {$ENDIF}
+  loadwithalteredsearchpath: Boolean;
 begin
   s := p.Decl;
   Delete(s, 1, 4);
   s2 := copy(s, 1, pos(#0, s)-1);
   delete(s, 1, length(s2)+1);
   h := makehash(s2);
+  s3 := copy(s, 1, pos(#0, s)-1);
+  delete(s, 1, length(s3)+1);
+  loadwithalteredsearchpath := bytebool(s[3]);
   i := 2147483647; // maxint
   dllhandle := 0;
   repeat
@@ -113,7 +117,10 @@
       {$IFDEF LINUX}
       dllhandle := dlopen(PChar(s2), RTLD_LAZY);
       {$ELSE}
-      dllhandle := LoadLibrary(Pchar(s2));
+      if loadwithalteredsearchpath then
+        dllhandle := LoadLibraryEx(Pchar(s2), 0, LOAD_WITH_ALTERED_SEARCH_PATH)
+      else
+        dllhandle := LoadLibrary(Pchar(s2));
       {$ENDIF}
       if dllhandle = {$IFDEF LINUX}nil{$ELSE}0{$ENDIF}then
       begin
@@ -133,9 +140,9 @@
     end;
   until dllhandle <> {$IFDEF LINUX}nil{$ELSE}0{$ENDIF};
   {$IFDEF LINUX}
-  p.Ext1 := dlsym(dllhandle, pchar(copy(s, 1, pos(#0, s)-1)));
+  p.Ext1 := dlsym(dllhandle, pchar(s3));
   {$ELSE}
-  p.Ext1 := GetProcAddress(dllhandle, pchar(copy(s, 1, pos(#0, s)-1)));
+  p.Ext1 := GetProcAddress(dllhandle, pchar(s3));
   {$ENDIF}
   if p.Ext1 = nil then
   begin
@@ -179,7 +186,7 @@
     exit;
   end;
   cc := TPSCallingConvention(s[1]);
-  delete(s, 1, 2); // cc + delayload (delayload might also be forced!)
+  delete(s, 1, 3); // cc + delayload + alternatesearchpath (delayload might also be forced!)
   CurrStack := Cardinal(Stack.Count) - Cardinal(length(s));
   if s[1] = #0 then inc(CurrStack);
   MyList := tIfList.Create;
