如何在VB6中模拟.net Int64?

2024-03-30

如何在 VB6 中存储 Int64 数字以与 Win32 函数一起使用?
有没有办法在.net中定义像Int64这样的类型?并简单评估一下数字。


我认为许多 VB6 程序员都需要这样的东西,
因为一些 Win32 API 使用 _int64 作为参数。

我编写了一个函数,将货币转换为 API 兼容的结构。
将这些代码放入模块文件中。

Private Declare Sub CopyMemory lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const SIZEOF_INT64 As Long = 8

Public Type Int64 'LowPart must be the first one in LittleEndian systems
    'required part
    LowPart  As Long
    HighPart As Long

    'optional part
    SignBit As Byte 'define this as long if you want to get minimum CPU access time.
End Type
'with the SignBit you can emulate both Int64 and UInt64 without changing the real sign bit in HighPart.
'but if you want to change it you can access it like this  mySign = (myVar.HighPart And &H80000000;)
'or turn on the sign bit using  myVar.HighPart = (myVar.HighPart Or &H80000000;)

Public Function CInt64(ByVal vCur As Currency) As Int64
    vCur = (CCur(vCur) * 0.0001@)
    Call CopyMemory(CInt64, vCur, SIZEOF_INT64)
End Function


现在您可以简单地使用 CInt64 创建一个 Int64 数字。
ex:


myRetVal = Win32APIFunctionWithOneInt64Param(CInt64(10000000))

'----OR

Dim myNum As Int64
myNum = CInt64(10000000)


对于更多操作:


Public Sub Op_Ev(Dest As Int64, Src As Int64) 'for setting the value.
    Call CopyMemory(Dest, Src, SIZEOF_INT64)
End Sub
Public Function Op_Eq(V1 As Int64, V2 As Int64) As Boolean 'for equal comparison.
    Op_Eq = (V1.LowPart = V2.LowPart)   : If Not Op_Eq Then Exit Function
    Op_Eq = (V1.HighPart = V2.HighPart)
End Function
Public Function Op_Gr(V1 As Int64, V2 As Int64, Optional ByVal IsUnsignedComparison As Boolean = False) As Boolean 'for grater comparison.
    If IsUnsignedComparison Then
        Dim H1 As Long, H2 As Long 'don't change the location of these definitions to optimize the function to prevent to execute two or more {SUB ESP, 4}
        H1 = (V1.HighPart And &H7FFFFFFF)   : H2 = (V2.HighPart And &H7FFFFFFF)
        Op_Gr = (H1 > H2)                   : If (H1 <> H2) Then Exit Function
        Dim HBS1 As Long, HBS2 As Long 'don't change the type of these two vars to byte to keep alignment for local variables.
        HBS1 = ((V1.HighPart And &H80000000) / &H80000000) 'export the sign bit and shift it to the right.
        HBS2 = ((V2.HighPart And &H80000000) / &H80000000) 'export the sign bit and shift it to the right.
        Op_Gr = (HBS1 > HBS2)               : If (HBS1 <> HBS2) Then Exit Function
    Else
        Op_Gr = (V1.HighPart > V2.HighPart) : If (V1.HighPart <> V2.HighPart) Then Exit Function
    End If
    Op_Gr = (V1.LowPart > V2.LowPart)
End Function
Public Function Op_Ls(V1 As Int64, V2 As Int64, Optional ByVal IsUnsignedComparison As Boolean = False) As Boolean 'for less comparison.
    If IsUnsignedComparison Then
        Dim H1 As Long, H2 As Long 'don't change the location of these definitions to optimize the function to prevent to execute two or more {SUB ESP, 4}
        H1 = (V1.HighPart And &H7FFFFFFF)   : H2 = (V2.HighPart And &H7FFFFFFF)
        Op_Ls = (H1 < H2)                   : If (H1 <> H2) Then Exit Function
        Dim HBS1 As Long, HBS2 As Long 'don't change the type of these two vars to byte to keep alignment for local variables.
        HBS1 = ((V1.HighPart And &H80000000) / &H80000000) 'export the sign bit and shift it to the right.
        HBS2 = ((V2.HighPart And &H80000000) / &H80000000) 'export the sign bit and shift it to the right.
        Op_Ls = (HBS1 < HBS2)               : If (HBS1 <> HBS2) Then Exit Function
    Else
        Op_Ls = (V1.HighPart < V2.HighPart) : If (V1.HighPart <> V2.HighPart) Then Exit Function
    End If
    Op_Ls = (V1.LowPart < V2.LowPart)
End Function
Public Function Op_Cmp(V1 As Int64, V2 As Int64, Optional ByVal IsUnsignedComparison As Boolean = False) As Long 'for comparison.
    If Op_Gr(V1, V2, IsUnsignedComparison) Then
        Op_Cmp = 1
    ElseIf Op_Ls(V1, V2, IsUnsignedComparison) Then
        Op_Cmp = -1
    Else
        Op_Cmp = 0
    End If
End Function
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在VB6中模拟.net Int64? 的相关文章

随机推荐

  • 在 Vue.js 中隐藏组件

    有没有办法可以控制共享组件在另一个组件中的渲染 我有一个组件 它是一个底部栏 需要在一些具体组件中禁用 不渲染 我正在所有组件都使用的模板中渲染底部栏 编辑 我正在使用 webpack 正如罗伊所说 您可以拥有一个属性来调节组件的渲染 假设
  • SDL-Mixer 音频在启动 Reactive-Banana 输入循环时停止

    我一直在开发一款使用多个音轨的游戏 其音量根据鼠标运动实时调整 我一般使用 SDl Mixer 来处理音频 使用 Reactive Banana 来处理游戏 问题是 一开始就开始播放的曲目在输入循环开始时停止播放 原因可能是其他原因 但我想
  • 如何在powershell中进行TDD和单元测试?

    随着微软将 powershell 强加到所有新的服务器产品中 我开始 不情愿地 认为我需要认真对待它 认真对待 的一部分是 TDD 您是否找到了对 Power shell 脚本进行单元测试的好方法 我找到了嘲笑的样本极客噪音先生 http
  • Spring Boot:如何使用 @Validated 注释在 JUnit 中测试服务?

    我正在尝试为我的 Spring Boot 应用程序构建一组约束验证器 我想构建一些验证注释 例如 NotNull 顺便说一句 验证应该支持验证组 所以我有一个带有验证注释的简单项目模型 public class Item NotNull g
  • 如何在Android中为整个应用程序设置背景?

    在我的应用程序中 我有很多层 我不想为每个层设置背景图像 而是想一劳永逸地设置背景 我怎样才能做到这一点 看一眼将主题应用于活动或应用程序 http developer android com guide topics ui themes
  • 自定义配置设置,自定义ClientSettingsSection

    考虑以下配置部分
  • 在 Raspberry Pi 中解码视频而不使用 OpenMAX?

    我正在寻找在 Raspberry Pi 上解码视频的示例directly 不使用 OpenMAX 这解释了多媒体软件的不同层 还有一个此处未显示的附加层 即 MMAL https github com raspberrypi userlan
  • 远程拒绝主控 -> 主控(预接收挂钩拒绝)

    我正在使用 Rails 3 2 当我尝试推送到 heroku 时收到错误 git push heroku master Counting objects 496 done Delta compression using up to 8 th
  • 应用程序中的 Firestore 查询给出权限被拒绝,而模拟器工作正常

    在我的基于 Firestore 的应用程序中 我使用以下查询来检索一些数据 FirebaseFirestore getInstance collection events document eventId collection instan
  • 如何只获取用户路径变量?

    Echo PATH 回报system路径变量 user路径变量 如何只得到user路径变量 The system PATH变量的值存储在 Windows 注册表中Path类型的REG EXPAND SZ包含对环境变量的引用 例如 Syste
  • 如何在 JSON 文件中进行搜索?

    如何创建一个搜索表单来搜索 JSON 文件中输入的术语 因此 如果搜索词等于位置对象内的标题 它应该返回该对象信息 如果没有匹配 则向用户反馈没有找到项目 我创建了一个搜索输入
  • 当您不需要将某些内容定义为动态来 with-redefs 时,将某些内容定义为动态的意义何在?

    在我看来 这with redefs可以做一切binding动态符号可以做到 只是它没有需要的限制 dynamic元数据 那么我什么时候应该使用其中一种而不是另一种呢 除了要求 dynamic元数据 binding还创建仅在当前线程中可见的绑
  • 如何从 Azure 函数返回 xlsx 文件?

    我见过一些人尝试过 我无法重现他们的结果 乐于使用任何语言 我可以从 HTTP 触发器创建 xlsx 我想从另一个 HTTP 触发器返回该文件 如果您已经生成了该文件 则返回它只是创建一个带有附件的 HTTP 响应 var result n
  • 使用 Python 字典作为键(非嵌套)

    Python 不允许将字典用作其他字典中的键 是否有使用非嵌套字典作为键的解决方法 更复杂的不可散列对象和我的具体用例的一般问题是搬到这里 https stackoverflow com questions 1611797 using no
  • C++ 模板参数更改对指针的引用

    也许我不知道如何搜索 但事实上我找不到任何人谈论这个 我的结构有一个non type论证取决于type争论 template lt typename SpecType SpecType NonType gt struct Struct Wh
  • yii 自定义错误页面,例如 404、403、500

    我正在尝试为所有错误消息创建单独的文件 404 403 500 等 这样我就可以为它们进行定制设计 如果可能的话 我不希望页眉和页脚也包含在我的错误页面中 现在我有这个 在我的站点控制器 php并把错误404 php进入我的浏览量 站点 f
  • 如何分析 Java 中的线程?

    我的应用程序中有生产者和消费者线程 我需要对它们进行分析以查看线程的性能 每个线程进入睡眠和等待之前所花费的时间等 并采取纠正措施以提高应用程序的整体效率 关于如何解决这个问题有什么建议吗 我个人使用 YourKit java profil
  • 在 Django 中接受电子邮件地址作为用户名

    有没有一种好方法可以在 Django 中执行此操作 而无需滚动我自己的身份验证系统 我希望用户名是用户的电子邮件地址 而不是他们创建用户名 请指教 对于其他想要这样做的人 我建议看一下django 电子邮件作为用户名 https githu
  • 使用 docker 和 --privileged 构建

    我在用着本指南 https aws amazon com blogs ai build a voice kit with amazon lex and a raspberry pi 使用 Amazon Lex 和 Raspberry Pi
  • 如何在VB6中模拟.net Int64?

    如何在 VB6 中存储 Int64 数字以与 Win32 函数一起使用 有没有办法在 net中定义像Int64这样的类型 并简单评估一下数字 我认为许多 VB6 程序员都需要这样的东西 因为一些 Win32 API 使用 int64 作为参