乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 65|回复: 3

[编程交流] 代码无法正常工作

[复制链接]

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 21:55:17 | 显示全部楼层 |阅读模式
几年来,我一直在我的代码中使用以下函数,现在在32位版本的AutoCAD上,现在我的公司正在切换到64位,我很难让它工作。如果有人有时间看一看,看看他们是否知道为什么它可能无法正常工作,我将不胜感激。非常感谢。
 
  1. Function GetCurrentPrinters() As Variant
  2.    
  3.    Dim Buffer() As Long
  4.    Dim PrintInfo() As PRINTER_INFO_4
  5.    Dim NumBytes As Long, NumNeeded As Long, NumPrinters As Long
  6.    Dim RetVal As Long, c As Long, Success As Boolean
  7.    Dim AllPrinters() As String
  8.    
  9.    NumBytes = 3072
  10.    ReDim Buffer(0 To (NumBytes \ 4) - 1) As Long
  11.    
  12.    Success = EnumPrinters(PRINTER_ENUM_LOCAL + PRINTER_ENUM_CONNECTIONS, "", 4, Buffer(0), NumBytes, NumNeeded, NumPrinters)
  13.    If Success Then
  14.        If NumNeeded > NumBytes Then
  15.            NumBytes = NumNeeded
  16.            ReDim Buffer(0 To (NumBytes \ 4) - 1) As Long
  17.            Success = EnumPrinters(PRINTER_ENUM_LOCAL + PRINTER_ENUM_CONNECTIONS, "", 4, Buffer(0), NumBytes, NumNeeded, NumPrinters)
  18.            If Not Success Then
  19.                MsgBox "Error Enumerating Printers", vbInformation, "Message"
  20.            End If
  21.        End If
  22.    Else
  23.        MsgBox "Error Enumerating Printers", vbInformation, "Message"
  24.    End If
  25.    If Success And NumPrinters > 0 Then
  26.        ReDim PrintInfo(0 To NumPrinters - 1) As PRINTER_INFO_4
  27.        For c = 0 To NumPrinters - 1
  28.            PrintInfo(c).pPrinterName = Space(StrLen(Buffer(c * 3)))
  29.            RetVal = PtrToStr(PrintInfo(c).pPrinterName, Buffer(c * 3))
  30.            PrintInfo(c).pServerName = Space(StrLen(Buffer(c * 3 + 1)))
  31.            RetVal = PtrToStr(PrintInfo(c).pServerName, Buffer(c * 3 + 1))
  32.            PrintInfo(c).Attributes = Buffer(c * 3 + 2)
  33.            
  34.        Next c
  35.       
  36. ReDim Preserve AllPrinters(NumPrinters)
  37.        For c = 0 To NumPrinters - 1
  38.       
  39.            
  40.            AllPrinters(c) = PrintInfo(c).pPrinterName
  41.            
  42.        Next c
  43.    Else
  44.        MsgBox "No Printers Found", vbInformation, "Message"
  45.    End If
  46.    GetCurrentPrinters = AllPrinters
  47.    
  48.    
  49. End Function
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 22:24:51 | 显示全部楼层
我有一个问题,vba 2013代码在2016年不工作简单的修复是vbaman打开代码得到了工具,然后参考,在我的情况下,它有一个2013库文件链接,不再存在,取消复选框保存等,现在工作良好。
回复

使用道具 举报

11

主题

40

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
83
发表于 2022-7-6 22:41:34 | 显示全部楼层
LongPtr与Long
 
http://blog.nkadesign.com/2013/vba-for-32-and-64-bit-systems/
回复

使用道具 举报

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 22:57:41 | 显示全部楼层
感谢BIGAL和yosso的回复。我试过你的两个建议,但不幸的是,两个似乎都不起作用。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 13:49 , Processed in 0.658752 second(s), 60 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表