I am writing a vba application using macros. I am trying to read a dword value for IMAP Port using RegQueryValueEx. The call succeeds but I lpcbData points to 0. Here is my declaration

Private Declare PtrSafe Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExW" (ByVal hKey As LongPtr, ByVal lpValueName As LongPtr, ByVal lpReserved As LongPtr, lpType As LongPtr, ByVal lpData As LongPtr, lpcbData As LongPtr) As LongPtr



If RegQueryValueExStr(hKey, StrPtr(queryFieldName), 0, dwType, port, dwBufSize) = ERROR_SUCCESS Then
      Dim wport As String
      'wport = StrConv(port, vbUnicode)
      EnumerateAccounts = EnumerateAccounts & fieldvalue & ": " & wport & "\n\r"
End If

The code above is not very well written, im just trying to hack some code together to read the port value. I have the same code working in a C++ application so it is not the issue of 32/64bit windows.

没有正确的解决方案

其他提示

Ok so i found out why it was returning a zero. First of all the dword values are/were stored using ASCII not unicode. In case someone else runs into the same problem, the correct declaration is as follows:

Private Declare PtrSafe Function RegQueryValueExDword Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal lpReserved As LongPtr, lpType As LongPtr, lpData As Any, lpcbData As LongPtr) As LongPtr

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top