I had to convert color picker code from a 32 bit call to 64 bit. Below is my simplified version for testing and discussion here. Normally I would put the array "dim" / declaration inside the function (just trying to avoid those comments).
In reviewing I ran across... "VarPtr" - This seems to be fetching a reference to a variable. However I read something that said VarPtr does not work with arrays but the below does run... This is far down in the weeds for me. Is this a valid way of doing this? If VarPtr does work with arrays, great it works I get it, if not, it is just getting some random memory address... What I have not done is trying to set the custom colors in the box the dialog that pops up. It seems that could corrupt memory if Varptr isn't doing what it is intended and I remote into my 64 bit office machine so if I kill it, it is bad.
In reviewing I ran across... "VarPtr" - This seems to be fetching a reference to a variable. However I read something that said VarPtr does not work with arrays but the below does run... This is far down in the weeds for me. Is this a valid way of doing this? If VarPtr does work with arrays, great it works I get it, if not, it is just getting some random memory address... What I have not done is trying to set the custom colors in the box the dialog that pops up. It seems that could corrupt memory if Varptr isn't doing what it is intended and I remote into my 64 bit office machine so if I kill it, it is bad.
Code:
Option Compare Database
Option Explicit
#If VBA7 Then
Private Type typChooseColor '20150211 Moved inside Compile directive and updated to use LongPtr where appropriate
lStructSize As Long
hwndOwner As LongPtr
hInstance As LongPtr
rgbResult As Long
lpCustColors As LongPtr
flags As Long
lCustData As LongPtr
lpfnHook As LongPtr
lpTemplateName As String
End Type
Private Declare PtrSafe Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (lpcc As typChooseColor) As LongPtr
#Else
Private Type typChooseColor '20150211 Moved inside Compile directive
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (lpcc As typChooseColor) As Long
#End If
Private Const CC_ANYCOLOR As Long = &H100
Private a_lngCustom(0 To 15) As Long 'You can fill this array with up to 16 color constants
Function GetColorFromPicker() As Long
Dim cc As typChooseColor
With cc
.lStructSize = LenB(cc)
.flags = CC_ANYCOLOR
.rgbResult = 0
.hwndOwner = Application.hWndAccessApp
'-----------------------
.lpCustColors = VarPtr(a_lngCustom(0)) 'This Runs but is it Right?
'-----------------------
End With
If ChooseColor(cc) = 1 Then ' chossecolor is a API for the color picker popup
GetColorFromPicker = cc.rgbResult
End If
End Function