gpt4 book ai didi

vba - Access 2010 VBA ptrVar无法正常工作

转载 作者:行者123 更新时间:2023-12-02 10:44:43 24 4
gpt4 key购买 nike

我在Access 2010中的VBA代码有问题。我声明了一个类型,但是当我尝试获取该类型的变量的指针(使用VarPtr函数)时,我得到了compilation error: incompatible type

Dim dm As DEVMODE
Dim pd As PRINTER_DEFAULTS

pd.pDevMode = VarPtr(dm) ' the line that throws the error

' pDevMOde is a Long that is supose to contain the adress of the dm variable

Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME ' (1 To CCHDEVICENAME) As Byte
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME '(1 To CCHFORMNAME) As Byte
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

问题在于该代码是在Access的早期版本中创建的,并且在2003及更低版本中可以正常使用。我不知道为什么它在Access 2010中不起作用。我查看了2010和2003版本之间的区别,但是没有发现与此相关的任何内容。

有人知道吗?

谢谢!

最佳答案

我终于找到了问题。
实际上64位版本有所不同。 VarPtr不再返回
Long类型,它返回LongPtr类型变量,我的代码无法将LongPtr放入Long

在这里引用:http://msdn.microsoft.com/en-us/library/ee691831.aspx

VarPtr | Variant converter. | Returns a LongPtr on 64-bit versions, and a Long on 32-bit versions (4 bytes).



希望它对其他人有帮助!

关于vba - Access 2010 VBA ptrVar无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14071263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com