Fortran Coder

楼主: andy8496
打印 上一主题 下一主题

[讨论] 隐藏文件到exe中

[复制链接]

123

帖子

32

主题

0

精华

宗师

F 币
1562 元
贡献
795 点
板凳
 楼主| 发表于 2023-2-1 17:51:52 | 只看该作者
fcode 发表于 2023-2-1 16:52
windows系统的话,可以包含在 Resource 资源里。
然后通过 FindResourceEx,LoadResource,SizeofResource  ...

多谢回复!
这些是Windows的API?大致理解原理了,但是在Fortran中怎么用这些函数?能否帮忙做个Demo?

1967

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1370 元
贡献
581 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

沙发
发表于 2023-2-1 16:52:13 | 只看该作者
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



您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-18 19:27

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表