Mirror

How to play an AVI file from a resource DLL (Views: 100)


Problem/Question/Abstract:

I have an AVI as a resource that I want to play using TAnimate. In a standalone executable this works fine, but fails with a "Cannot Open AVI." error message. According to MSDN I should set the TAnimate ResHand to the instance handle of the DLL. How do I find this?

Answer:

It appears that trying to load an AVI from a resource causes an exception on the first attempt, so I gave it another go and it worked. Here's the code:


procedure TSplash.ShowSplash;
var
  ResHandle: Integer;
begin
  try
    ResHandle := LoadAviAsResource(Animate1, 'MyDll.dll', 'SPLASHAVI');
    { causes exception }
  except
    ResHandle := LoadAviAsResource(Animate1, 'MyDll.dll', 'SPLASHAVI');
    { this time it works }
  end;
  if ResHandle > 0 then
  begin
    Animate1.Visible := True;
    Animate1.Repetitions := -1;
    Animate1.Active := True
  end
  else
  begin
    Animate1.Visible := False;
    Animate1.Active := False;
    { Show a static bitmap or something if AVI cannot be displayed }
  end;
  Show;
end;

function TSplash.LoadAviAsResource(const AviName: TObject; DllName,
  ResourceName: string): Integer;
var
  ResourceHandle: THandle;
begin
  ResourceHandle := LoadLibrary(Pchar(DllName));
  TAnimate(AviName).ResName := ResourceName;
  TAnimate(AviName).ResHandle := ResourceHandle;
  FreeLibrary(ResourceHandle);
  result := ResourceHandle;
end;

<< Back to main page