vb Integer到c++到ML32到c++到vb UInteger
vb Integer to c++ to ML32 to c++ to vb UInteger
我正在尝试通过ML32中的直接逐位传输将vb 2015 Integer更改为vb 2015 UInteger。在vb2015中,我在dll中调用了一个vc++2015函数,该函数使用内联汇编程序来实现更改。
通过这样做,我可以得到一个负整数,例如633593090=&HDA3C22FE=11011010001111000010001011111110b
并将其更改为UInteger=111011010001111000010001011111110b=&HDA3C22FE=3661374206
与看似简单的"uTest1=CUInt(iTest1)"相反,它为iTest1负数抛出System.OverflowException。
我有可以正常工作的代码,但我对微小改进的可能性感兴趣。
在vb 2015中,我声明对vc++2015 dll的访问权限如下:
' vb Integer --> c++ signed long --> c++ unsigned long --> vb UInteger -- Works!
' by direct copy of bits through x86 ML32
' 4 bytes = 32 bits
<DllImport("StringTest.dll", EntryPoint:="bitConvert", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Private Shared Function bitConvertTester(ByRef varSInt As Integer, ByRef varUInt As UInteger) As Integer
' Must be "Shared"
' Must be "ByRef"
' Do not try varSInt As "Signed Integer" or varUInt As "Unsigned Integer" --> Syntax Error
' Leave the body of the function empty
End Function
我使用这个vb2015代码实际调用dll中的vc++2015函数:
' Third Method - Partial - Works!
Dim pCTest As Color
Dim iTest As Integer
Dim uTest As UInteger
Dim returnCode As Integer
pCTest = Color.FromArgb(&HDA, &H3C, &H22, &HFE)
iTest = pCTest.ToArgb
System.Diagnostics.Debug.Write(iTest.ToString + vbCrLf)
System.Diagnostics.Debug.Write(Hex(iTest) + vbCrLf)
' vb Integer --> c++ signed long --> c++ unsigned long --> vb UInteger
' by direct copy of bits through x86 ML32
' 4 bytes = 32 bits
' Note: Function prototype is "ByRef", but this MUST
' NOT go in this test call (causes a syntax error).
returnCode = bitConvertTester(iTest, uTest)
System.Diagnostics.Debug.Write(uTest.ToString + vbCrLf)
System.Diagnostics.Debug.Write(Hex(uTest) + vbCrLf)
这里是vc++2015 dll函数本身:
#define EXPORT_VB extern "C" __declspec(dllexport)
// vb Integer --> c++ signed long --> c++ unsigned long --> vb UInteger -- Works!
// by direct copy of bits through x86 ML32
// 4 bytes = 32 bits
EXPORT_VB long __cdecl bitConvert(signed long *varSInt, unsigned long *varUInt)
{
// Intermediate variables are required for ML32 access.
signed long varSInt1;
unsigned long varUInt1;
varSInt1 = *varSInt;
__asm
{
mov EAX, varSInt1
mov varUInt1, EAX
}
*varUInt = varUInt1;
return 1; // Success Code
}
我用变量ByRef从vb 2015调用了vc++2015 dll函数,这样dll函数就可以使用指针通过*varSInt和*varUInt根据需要更改vb 2015变量。
我的问题是:在vc++__asm块中,ML32代码是否有任何方法可以直接访问*varSInt和*varUInt,而不需要经过varSInt1和varUInt1中间变量?
顺便说一句,vb 2015代码使用:
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
并且vc++2015代码使用:
#include "stdafx.h"
#include <stdexcept>
#include <string.h>
(我对Microsoft文档感到沮丧的一件事是,它没有包含使用文档所描述的功能所需的"Imports"或"#include"语句的列表)。
我意识到你说过你只是在练习,但有一种相对简单的方法可以在VB(或C#)中获得你想要的结果。
Function ToUInt(value As Integer) As UInteger
Return CUInt(If(value < 0, UInteger.MaxValue + value + 1, value))
End Function
- 如何在 64 位 vb.net Windows 应用程序中引用 32 位 dll
- C++/CLI 和 C#/VB 与不安全和外部有什么区别?
- 如何将 VB.Net 字符串作为字符*传递给C++dll?
- 如何使用VB经典IDE在VB脚本中调试ActiveX应用程序
- VB.NET DLL中的C++DLL函数复制
- TEA在VB.NET中的实现
- 如何使函数返回数组?用于制作在VB.NET中使用的DLL
- 反调试器技术:如何使用 VB.NET 对调试器隐藏线程?
- 如何在C 调用的VB.NET中编写回调函数
- 我可以在 vb.net Windows 窗体应用程序中使用 COLECONTROLModule 吗?
- C++ DLL 包装器 vb.net 传递字节数组的字节数组?
- Arduino equivalent to VB WITH
- 将简单的程序从C++移植到 vb.net
- 内存损坏从vb.net调用c dll
- vb.net单不等于c float
- 导入C 功能将结构的指针返回到VB.NET中
- REGDB_E_CLASSNOTREG from VB.NET to C++
- 使用来自VB.NET的参数调用C 函数
- DLL不导出Visual Studio 2013 VB代码中的字符串
- 使用P/Invoke从MFC DLL函数中读取VB.NET中的结构化数据