Author: Tomas Rutkauskas
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:
1 procedure TSplash.ShowSplash;
2 var3 ResHandle: Integer;
4 begin5 try6 ResHandle := LoadAviAsResource(Animate1, 'MyDll.dll', 'SPLASHAVI');
7 { causes exception }8 except9 ResHandle := LoadAviAsResource(Animate1, 'MyDll.dll', 'SPLASHAVI');
10 { this time it works }11 end;
12 if ResHandle > 0 then13 begin14 Animate1.Visible := True;
15 Animate1.Repetitions := -1;
16 Animate1.Active := True
17 end18 else19 begin20 Animate1.Visible := False;
21 Animate1.Active := False;
22 { Show a static bitmap or something if AVI cannot be displayed }23 end;
24 Show;
25 end;
26 27 function TSplash.LoadAviAsResource(const AviName: TObject; DllName,
28 ResourceName: string): Integer;
29 var30 ResourceHandle: THandle;
31 begin32 ResourceHandle := LoadLibrary(Pchar(DllName));
33 TAnimate(AviName).ResName := ResourceName;
34 TAnimate(AviName).ResHandle := ResourceHandle;
35 FreeLibrary(ResourceHandle);
36 result := ResourceHandle;
37 end;