This is because we only need to use the LongPtr data type if the function arguments or return values that are memory addresses, if they represent data you should still use the Long data type. Let’s look at another example: ‘API definition the old wayĭeclare Function GetKeyState Lib "USER32" ( ByVal vKey As Long) As Integerĭeclare PtrSafe Function GetKeyState Lib "USER32" ( ByVal vKey As Long) As IntegerNotice anything different? Here we only used the keyword PtrSafe but did not change the Long data type to LongPtr. We have changed the Long data type to LongPtr, and have said that WinAPI call is now safe by using the PtrSafe keyword. I have bolded and underlined the changes to make them easy to see. Private Declare PtrSafe Function GetDC Lib "USER32" ( ByVal hWnd As LongPtr) As LongPtr Private Declare Function GetDC Lib "USER32" ( ByVal hWnd As Long) As Long Here is an example of the changes that will need to be made. Without this keyword any function / subroutine with Declare will fail to compile. This way VBA know you have reviewed the call and made it safe. VBA needs to know that you have reviewed the WinAPI calls and made the correct changes to the new LongPtr data type, so Microsoft added the keyword PtrSafe to VBA to add after the Declare statement. The LongPtr data type will work correctly on both 32 and 64-bit systems as it uses a 32-bit pointer size for 32-bit platforms and a 64-bit pointer size for 64-bit platforms, pretty smart huh. Microsoft has added support for 64-bit by creating the new data type, LongPtr in VBA 7. If VBA where passed a 64-bit value it would be truncated to a 32-bit value when making the WinAPI call and most likely lead to a crash of the host application, in our case CorelDRAW. VBA needs to pass 64-bit values to the parameters and return values, not 32-bit as in the past. As they say, you cannot put a 64-bit value in a 32-bit bucket, it will not fit. The Long data type is a 32-bit Integer, on a 64-bit platform the pointers are 64-bit values. VBA has used the Long data type to represent pointer values in WinAPI calls.
This is only for the 64-bit version, if you are using the 32-bit version of CorelDRAW, even on a 64-bit version of Windows everything should run as expected.
All previous macros that use WinAPI calls will need to be updated for CorelDRAW X6 (64-bit). The one exception to this are macros that use WinAPI calls. The good news in most macros from previous versions of CorelDRAW should work great.