2010-03-03 4 views
0

ResResource, LoadResource 및 LockResource를 사용하여 res 파일의 리소스에 액세스했습니다. Delphi 애플리케이션을 통해 추출 및 재생할 웨이브 파일이 있습니다.Delphi 리소스 파일에서 파일을 추출하지 못했습니다.

나는 추출하지 않고 해냈지만,하고 싶은 일이 아닙니다. 먼저 웨이브 파일을 추출하고 싶습니다. 누구든지 올바른 해결책을 제시 할 수 있습니까?

답변

3

TResourceStream 클래스를 사용하여 WAVE 리소스를로드하고 SaveToFile 메서드를 사용하여 디스크에 저장할 수 있습니다.

6

이미 LoadResourceLockResource을 호출 중이라면 이미 중간에 있습니다. LockResource은 리소스 데이터의 첫 번째 바이트에 대한 포인터를 제공합니다. SizeofResource에 전화하여 몇 바이트가 있는지 확인하고 다른 블록에 복사하거나 파일에 기록하는 등 원하는 메모리 블록을 수행 할 수 있습니다. 다른 메모리 블록에

resinfo := FindResource(module, MakeIntResource(resid), type); 
hres := LoadResource(module, resinfo); 
pres := LockResource(module, hres); 
// The following is the only new line in your code. You should 
// already have code like the above. 
size := SizeofResource(module, resinfo); 

복사 : 파일에

var 
    buffer: TBytes; 

SetLength(buffer, size); 
Move(pres^, buffer[0], size); 

쓰기 :

PlaySound(MakeIntResource(resid), module, snd_Resource); 
PlaySound(PChar(pres), 0, snd_Memory); 
PlaySound(PChar(@buffer[0]), 0, snd_Memory); 
PlaySound('foo.wav', 0, snd_FileName); 
이 우리에게 그 웨이브 데이터를 재생할 수있는 몇 가지 방법을 제공합니다

var 
    fs: TStream; 

fs := TFileStream.Create('foo.wav', fmCreate); 
try 
    fs.Write(pres^, size); 
finally 
    fs.Free; 
end; 

관련 문제