Gracias por responder cHackAll, ya encontré la forma de solucionar el problema:
Código Delphi
[-]
unit Global;
interface
uses Messages, Classes;
type
TPhxMessage = packed record
DestHandle: THandle;
Str: string[255];
end;
const
Mapping = 'OPAMS-14ASD-MU1EX';
Mutex = 'E51BA-9QIOSAD-PHOENIX';
WM_TRANSFER = WM_USER + 1;
var
Index: integer = 0;
UpdateOpen: boolean = false;
UpdateSlider: boolean = false;
WiniPath: string;
PhxMessage : ^TPhxMessage;
mhandle, nHandle: THandle;
CustomList: TStringList;
Sychronized: boolean = true;
implementation
end.
Código Delphi
[-]
program phxmp;
uses
ComCtrls,
Forms, Classes,
XPMan, Messages,
SysUtils, Windows, dialogs,
frm_main in 'frm_main.pas' ,
frm_skins in 'frm_skins.pas' ,
PlayerUtils in 'PlayerUtils.pas',
Global in 'Global.pas',
uThreadFiles in 'uThreadFiles.pas',
uPlayList in 'uPlayList.pas';
{$R *.res}
begin
WiniPath:= ExtractFilePath(paramstr(0)) + 'Options.ini';
Application.Initialize;
Application.CreateForm(TFMain, FMain);
Application.CreateForm(TFSkins, FSkins);
CreateMutex(nil, True, Mutex);
if GetLastError = ERROR_ALREADY_EXISTS then
begin
if ParamCount = 1 then
begin
nHandle:=OpenFileMapping(FILE_MAP_ALL_ACCESS,False, pchar(Mapping));
if nHandle = 0 then raise Exception.Create('Error ¿?');
PhxMessage:= MapViewOfFile(nHandle,FILE_MAP_ALL_ACCESS,0,0,0);
PhxMessage^.Str:= paramstr(1);
PostMessage(PhxMessage^.DestHandle, WM_TRANSFER, 0 ,0);
UnmapViewOfFile(PhxMessage);
CloseHandle(nHandle);
end;
ExitProcess(0);
end else
begin
mHandle:= CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0, SizeOf(TPhxMessage), pchar(Mapping));
PhxMessage:=MapViewOfFile(mHandle, FILE_MAP_WRITE,0,0,0);
PhxMessage^.DestHandle:= FMain.Handle;
end;
Application.Title:= 'Phoenix Media Player';
Application.Run;
end.
Y después en el Form:
Código Delphi
[-]
public
procedure HookMessage (var Msg: TMessage); message WM_TRANSFER;
end;
var
FMain: TFMain;
implementation
{$R *.dfm}
procedure TFMain.HookMessage(var Msg: TMessage);
var
Thread: TMFThread;
begin
if CheckCompability(PhxMessage^.Str) = true then
begin
CustomList.Add(PhxMessage^.Str);
Thread:=TMFThread.Create(CustomList);
CustomList.Clear;
end;
end;
Funciona perfectamente, registro las extensiones en el registro y solo se abre un única instancia de mi aplicación. Pero me surge un error, cuando abro muchos archivos por la sincronización de los thread que espero resolver pronto.
Muchas gracias
Saludos.
PD: Tengo que resolver el problema del BufferOverflow...