好的,我改得严谨一点,可以兼容x86和x64。
另外,你可以尝试在 rc 文件里包含一个 ico 图标,和版权信息。不用写任何代码,就有效果。很有趣。
[Fortran] 纯文本查看 复制代码 Logical Function WriteResourceToFile( resType , resID , fileName ) result(ok)
use , intrinsic :: ISO_C_Binding
use kernel32 , only : WORD,LPVOID,HANDLE, &
SizeofResource , LockResource , LoadResource , FindResourceEx
Character(Len=*) , intent(IN) :: resType , fileName
Integer(LPVOID) , intent(IN) :: resID
integer(HANDLE) :: hRes,hMem
integer :: j
character(len=len_trim(resType)+1) :: myType
character , pointer :: pMem(:)
type(c_ptr) :: cp
ok = .false.
myType = trim(resType)//c_null_char
hRes = FindResourceEx(0_HANDLE,transfer(c_loc(myType),hRes),resID,0_WORD)
if( hRes == 0_HANDLE ) return
hMem = LoadResource(0_HANDLE,hRes)
if( hMem == 0_HANDLE ) return
hMem = LockResource( hMem )
if( hMem == 0_HANDLE ) return
j = SizeofResource(0_HANDLE,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
|