Hi Technomage,
I think I understood the problem, but I have still some problems..
I implemented getenv and putenv and now it compiles and links perfectly.
Code:
{$mode delphi}
unit getenv;
interface
uses
Classes, SysUtils;
function SDL_putenv(const variable: PChar): integer;
function SDL_getenv(const name: PChar): PChar;
function _putenv( const variable : Pchar ): integer;
function _getenv( const name : Pchar ): PChar;
function getenv( const name : Pchar ): PChar;
function putenv(const variable: PChar): integer;
implementation
type
REnv_var=record
name:string;
value:string;
end;
var
SDL_env: array of REnv_var;
{ Put a variable of the form "name=value" into the environment. }
function SDL_putenv(const variable: PChar): integer;
var
name, value: string;
i,added: integer;
env_var: REnv_var;
begin
if variable=nil then begin
result:=-1;
exit;
end;
name:= String(variable);
i:=Pos('=',name);
if (i=0) then begin
result:=-1;
exit;
end;
{ Take the values }
env_var.value:=Trim(Copy(name, i+1, Length(name)-i));
env_var.name:=Trim(Copy(name, 1, i-1));
{ Check the variable is not already in the environment.
If it is, replace it. }
added:=-1;
For i:=0 to Length(SDL_env)-1 do begin
if (SDL_env[i].name=env_var.name) then begin
SDL_env[i].value:=env_var.value;
added:=0;
Break;
end;
end;
if (added=-1) then begin
SetLength(SDL_env, Length(SDL_env)+1);
SDL_env[Length(SDL_env)-1].value:=env_var.value;
SDL_env[Length(SDL_env)-1].name:=env_var.name;
added:=0;
end;
Result:=added;
end;
function SDL_getenv(const name: PChar): PChar;
var
vname, venv: String;
i:integer;
begin
vname:=String(name);
For i:=0 to Length(SDL_env)-1 do begin
if (SDL_env[i].name=vname) then begin
venv:=SDL_env[i].name+'='+SDL_env[i].value;
Result:=PChar(venv);
break;
end;
end;
end;
function _putenv( const variable : Pchar ): integer;
begin
Result:=SDL_putenv(variable);
end;
function putenv( const variable : Pchar ): integer;
begin
Result:=SDL_putenv(variable);
end;
function _getenv( const name : Pchar ): PChar;
begin
Result:=SDL_getenv(name);
end;
function getenv( const name : Pchar ): PChar;
begin
Result:=SDL_getenv(name);
end;
end.
However, I get the following message whenever I try to execute the SDL-based application:
"The file 'project1' cannot be opened. Either it is not signed with a trusted certificate, or one of its components cannot be found. If the problem persists, try reinstalling or restoring this file."
I think it is because I still need a DLL (SDL.dll for WINCE), therefore I'm going to compile the original SDL for WINCE using a C compiler and see if it works. I will post my progress.
Best regards,
MoRLoP
Bookmarks