首页 > 解决方案 > 如何在 DOSBox 中运行的汇编程序中将文本插入剪贴板?

问题描述

我在程序集中有一个包含字符串的 db 变量,如下所示:

STR_VAR db 'test$'

是否可以将此变量复制到剪贴板,这样当用户在另一个程序(例如 word)中按下 Ctrl+V 时,它会将文本粘贴到变量中。

编辑:重要信息:我正在使用 DOSBox 运行代码

标签: assemblyx86clipboarddosdosbox

解决方案


实际上有一个用于 DOS 的官方 API 用于访问主机的剪贴板,在 Windows 3.x 和 9x 中受支持。它在文章Q67675中有简要描述,以前在 Microsoft 的知识库中。

这是一个代码示例(NASM 语法):

org 0x100

        mov     ax, 0x1700   ; IdentifyWinOldApVersion
        int     0x2f
        cmp     ax, 0x1700
        jz      error

        mov     ax, 0x1701   ; OpenClipboard
        int     0x2f
        test    ax, ax
        jz      error

        mov     ax, 0x1709   ; ClipboardCompact
        mov     cx, STR_VAR.end - STR_VAR
        xor     si, si
        int     0x2f
        cmp     dx, si
        jb      error
        ja      .fits
        cmp     cx, ax
        jb      error

.fits:
        mov     ax, 0x1703   ; SetClipboardData
        mov     dx, 7        ; CF_OEMTEXT
        mov     bx, STR_VAR
        ; ES and SI:CX already set up
        int     0x2f
        test    ax, ax
        jz      error
        
        mov     ax, 0x1708   ; CloseClipboard
        int     0x2f

        mov     ax, 0x4c00
        int     0x21

error:
        mov     ax, 0x4c01
        int     0x21

STR_VAR:
        db      'test'
.end:

然而,我非常怀疑 vanilla DOSBox 是否真的支持这个 API(尽管它显然在 DOSBox-X 中得到支持,一个分支)。


推荐阅读