windows系统的话,可以包含在 Resource 资源里。
然后通过 FindResourceEx,LoadResource,SizeofResource 这几个函数,得到资源体。Open , Write 到文件里去。
[Fortran] 纯文本查看 复制代码 Logical Function WriteResourceToFile( resType , resID , fileName ) result(ok)
use , intrinsic :: ISO_C_Binding
use kernel32 , only : SizeofResource , LockResource , LoadResource , FindResourceEx
Character(Len=*) , intent(IN) :: resType , fileName
Integer , intent(IN) :: resID
character(len=len_trim(resType)+1) :: myType
character , pointer :: pMem(:)
integer :: hRes,hMem, j
type(c_ptr) :: cp
ok = .false.
myType = trim(resType)//c_null_char
hRes = FindResourceEx(0,transfer(c_loc(myType),j),resID,0_2)
if( hRes == 0 ) return
hMem = LoadResource(0,hRes)
if( hMem == 0 ) return
hMem = LockResource( hMem )
if( hMem == 0 ) return
j = SizeofResource(0,hRes)
if( j == 0 ) return
call c_f_pointer( transfer( hMem , cp ) , pMem , [j] )
Open(NewUnit = j , File = fileName , access="stream")
write(j) pMem
Close(j)
ok = .true.
End Function WriteResourceToFile
|