Chỉnh code từ office 32bit thành 64bit
Em có file khi trước câc anh chị viết dùm trên Excel 32bit, giờ máy hư anh IT cài Excel 64bit, nên khi mở file cũ, trong file có sử dụng Form, thì lỗi dòng này:
Public Declare Function SetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long Public Declare Function GrayString Lib "user32" Alias "GrayStringA" (ByVal hdc As Long, ByVal hBrush As Long, ByVal lpOutputFunc As Long, ByVal lpData As Long, ByVal nCount As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Public Declare Function GetSysColor Lib "user32.dll" (ByVal nIndex As Long) As Long Public Declare Function GetSysColorBrush Lib "user32.dll" (ByVal nIndex As Long) As Long Public Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Public Declare Function GetTextExtentPointStr32 Lib "gdi32.dll" Alias "GetTextExtentPoint32W" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, ByRef lpSize As Size) As Long Public Declare Function GetTextExtentPoint32 Lib "gdi32.dll" Alias "GetTextExtentPoint32W" (ByVal hdc As Long, ByVal lpsz As Any, ByVal cbString As Long, ByRef lpSize As Size) As Long Public Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long Public Declare Function CreatePenIndirect Lib "gdi32.dll" (ByRef lpLogPen As LOGPEN) As Long Public Declare Function CreateBrushIndirect Lib "gdi32.dll" (ByRef lpLogBrush As LOGBRUSH) As Long Public Declare Function PatBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long Public Declare Function SetROP2 Lib "gdi32.dll" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long Public Declare Function GetROP2 Lib "gdi32.dll" (ByVal hdc As Long) As LongMong câc anh chị chỉnh dùm.
Bạn xem nhé:
#If VBA7 Then
Public Declare PtrSafe Function SetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Public Declare PtrSafe Function GrayString Lib "user32" Alias "GrayStringA" (ByVal hdc As Long, ByVal hBrush As Long, ByVal lpOutputFunc As Long, ByVal lpData As Long, ByVal nCount As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare PtrSafe Function GetSysColor Lib "user32.dll" (ByVal nIndex As Long) As Long
Public Declare PtrSafe Function GetSysColorBrush Lib "user32.dll" (ByVal nIndex As Long) As Long
Public Declare PtrSafe Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare PtrSafe Function GetTextExtentPointStr32 Lib "gdi32.dll" Alias "GetTextExtentPoint32W" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, ByRef lpSize As Size) As Long
Public Declare PtrSafe Function GetTextExtentPoint32 Lib "gdi32.dll" Alias "GetTextExtentPoint32W" (ByVal hdc As Long, ByVal lpsz As Any, ByVal cbString As Long, ByRef lpSize As Size) As Long
Public Declare PtrSafe Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Public Declare PtrSafe Function CreatePenIndirect Lib "gdi32.dll" (ByRef lpLogPen As LOGPEN) As Long
Public Declare PtrSafe Function CreateBrushIndirect Lib "gdi32.dll" (ByRef lpLogBrush As LOGBRUSH) As Long
Public Declare PtrSafe Function PatBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
Public Declare PtrSafe Function SetROP2 Lib "gdi32.dll" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long
Public Declare PtrSafe Function GetROP2 Lib "gdi32.dll" (ByVal hdc As Long) As Long
#Else
Public Declare PtrSafe Function SetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Public Declare PtrSafe Function GrayString Lib "user32" Alias "GrayStringA" (ByVal hdc As Long, ByVal hBrush As Long, ByVal lpOutputFunc As Long, ByVal lpData As Long, ByVal nCount As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare PtrSafe Function GetSysColor Lib "user32.dll" (ByVal nIndex As Long) As Long
Public Declare PtrSafe Function GetSysColorBrush Lib "user32.dll" (ByVal nIndex As Long) As Long
Public Declare PtrSafe Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare PtrSafe Function GetTextExtentPointStr32 Lib "gdi32.dll" Alias "GetTextExtentPoint32W" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, ByRef lpSize As Size) As Long
Public Declare PtrSafe Function GetTextExtentPoint32 Lib "gdi32.dll" Alias "GetTextExtentPoint32W" (ByVal hdc As Long, ByVal lpsz As Any, ByVal cbString As Long, ByRef lpSize As Size) As Long
Public Declare PtrSafe Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Public Declare PtrSafe Function CreatePenIndirect Lib "gdi32.dll" (ByRef lpLogPen As LOGPEN) As Long
Public Declare PtrSafe Function CreateBrushIndirect Lib "gdi32.dll" (ByRef lpLogBrush As LOGBRUSH) As Long
Public Declare PtrSafe Function PatBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
Public Declare PtrSafe Function SetROP2 Lib "gdi32.dll" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long
Public Declare PtrSafe Function GetROP2 Lib "gdi32.dll" (ByVal hdc As Long) As Long
#End If
Lần sau thì cứ theo cách:
#If VBA7 Then
'64bit
' Thêm "PtrSafe" trước Function
' sửa "As Long" thành "As LongPtr" ....
'Ham goi API
#Else
'32bit
'Ham goi API
#End If
Chết dở.
Không phải như thế bạn nhé.
Khai báo ra sao thì phải đọc hướng dẫn sử dụng, chứ không phải thêm cái từ khoá PtrSafe vào là được.
Con kiểu dữ liệu (Data type) LongPtr tùy từng tham số nữa nhé.
Tôi nhớ là còn phải sửa As Long thành As LongPtr ….
Tham khảo thêm bài của anh @ongke0711 luôn 😀
Nguồn: thuthuataccess.com/forum/thread-11224-post-43656.html#pid43656
Khi khai báo các hàm Windows API cho 64bit chỉ cần chú ý khai báo các giá trị Long đại điện cho các dữ liệu con trỏ (Pointer) hoặc bộ điều khiển (Handles).
– Các tham số, biến kiểu Pointer: có ký tự "lp" hoăc "l" ở đầu tên tham số.
lpdwFlasg As Long –> lpdwFlags As LongPtr
lpfnHook As Long –> lpfnHook As LongPtr
lParam As Long –> lParam As LongPtr
lCustData As Long –> lCustData As LongPtr
– Các tham số kiển điều khiển: có ký tự "h" ở đầu
hWnd As Long –> hwnd As LongPtr
hProcess As Long –> hProcess As LongPtr
hThread As Long –> hThread As LongPtr
Ủa, Handles dịch là bộ điều khiển à?
Hồi nào giờ tôi dịch là trao/nhận việc.
Em trích lại chứ em cũng không biết dịch chính xác là gì nữa 😀
Bộ điều khiển, trình xử lý, … Có lẽ sợ nhầm lẫn nên bài trích cũng (thuật ngữ tiếng Anh).
Anh nói làm em tìm hiểu một chập cuối cùng cũng không biết phải gọi là gì:
stackoverflow.com/a/13023487
A handle is usually an opaque reference to an object. …
Handles can only be used by functions in the same library interface, that can remap the handle back to the actual object.
stackoverflow.com/a/13023473
Basic meaning of a handle is that it refers to some object in very limited context; eg. an OS can keep only 20 files opened for a user or pid. A pointer refers to the same object in the context of "memory". And reference is an "alias" to an object — it refers to an object in the context of source code; thus reference to a reference doesn't exists as a reference already "is" the object.
www.giaiphapexcel.com/diendan/threads/ch%E1%BB%89nh-code-t%E1%BB%AB-office-32bit-th%C3%A0nh-64bit.163350/post-1089662
Em trích lại chứ em cũng không biết dịch chính xác là gì nữa 😀
Bộ điều khiển, trình xử lý, … Có lẽ sợ nhầm lẫn nên bài trích cũng (thuật ngữ tiếng Anh).Anh nói làm em tìm hiểu một chập cuối cùng cũng không biết phải gọi là gì:
…Stackoverflow bây giờ cũng hơi xưa rồi. Có nhiều pho-rum mới, tân tiến hơn về thuật ngữ.
Bài trong trích dẫn của bạn là viết năm 2012 – xấp xỉ 10 năm. Ngoài ra, họ viết trong ngữ cảnh C++, không phải VB.
Theo lập trình chung thì handle là con trỏ gọi hàm hoặc object chứa cái hàm mà người ta cần để trao cho việc, hoặc để nhận việc được trao.
Khóa học Power PI – Ứng dung trong Nhân sự
TỔNG QUAN KHÓA HỌC: POWER BI CHO NGÀNH NHÂN SỰ Khóa học Power BI cho Nhân sự được thiết kế dành riêng cho các...
Xem khóa học
Bình luận