Chỉnh code từ office 32bit thành 64bit

Liên hệ QC

NguyenthiH

Thành viên mới đăng ký
Tham gia
11/12/16
Bài viết
949
Được thích
175
Giới tính
Nữ
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:
Mã:
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 Long
Mong câc anh chị chỉnh dùm.
 
Bạn xem nhé:
PHP:
#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:
PHP:
#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
 
Lần chỉnh sửa cuối:
Upvote 0
Tham khảo thêm bài của anh @ongke0711 luôn :D
Nguồn: https://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
 
Upvote 0
...
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).
Ủ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.
 
Upvote 0
Ủ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 :D
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ì:

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.

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.
 
Upvote 0
Em trích lại chứ em cũng không biết dịch chính xác là gì nữa :D
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.
 
Lần chỉnh sửa cuối:
Upvote 0
Em mày mò mãi unintall cái Office 2016 64bit đi, và tải office 2016 32bit về và cài đặt, sao đã Active rồi mà trên dòng tên của Excel vẫn là Product Activation failedUntitled.png
và mỗi lần mở hiện bảng
Untitled_1.png
mong các anh chị giúp đỡ.
 
Upvote 0
Các anh, chị cho em hỏi, nhìn vào 1 đoạn code thì làm sao biết được code chạy trên 32 bit hay 64 bit. Em cảm ơn!
 
Upvote 0
Chổ code này thì chỉnh thành 64bit làm sao các anh???
Mã:
Private Declare Sub CopyMemoryByte Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, ByVal Source As Long, ByVal Length As Long)
Private Declare Sub CopyMemoryWord Lib "kernel32" Alias "RtlMoveMemory" (Destination As Integer, ByVal Source As Long, ByVal Length As Long)

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, Source As Any, ByVal Length As Long)
Mã:
Public Declare Sub DrawStatusText Lib "comctl32.dll" (ByVal hdc As Long, ByRef lprc As RECT, ByVal pszText As String, ByVal uFlags As Longptr)
 
Lần chỉnh sửa cuối:
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom