Numeric values of WinHTTP constants (eg. WINHTTP_NO_CLIENT_CERT_CONTEXT) - vb6

I need to set this property for a WinHttp request...
BOOL fRet = WinHttpSetOption(hRequest,
WINHTTP_OPTION_CLIENT_CERT_CONTEXT,
WINHTTP_NO_CLIENT_CERT_CONTEXT,
0);
But from within an old VB application. I can access the method but can't use the constants.
I can use this to access the method from VB...
Declare Function WinHttpSetOption Lib "winhttp.dll" _
(ByVal hInternet As Variant, ByVal dwOption As Integer, ByVal lpBuffer As Byte, ByVal dwBufferLength As Integer) _
As Boolean
And then call it like so...
Call WinHttpSetOption(hRequest, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, WINHTTP_NO_CLIENT_CERT_CONTEXT, 0);
But have to replace the constants WINHTTP_OPTION_CLIENT_CERT_CONTEXT and WINHTTP_NO_CLIENT_CERT_CONTEXT with the correct numbers, or figure out how to import them.
After I long google search, I think WINHTTP_OPTION_CLIENT_CERT_CONTEXT is 47 but can't find WINHTTP_NO_CLIENT_CERT_CONTEXT anywhere.
Many thanks

Related

How to find correct values for HWND window handles?

WinRestore,% hwnd([1])
i have found in many programming language the use of hwnd. after searching on google it comes out to be handle. I didnt got more information on this. how programmer knows the value to put in, eg.
Const LB_GETTEXTLEN = &H18A
Const LB_GETTEXT = &H189
Const LB_GETCOUNT = &H18B
&h18a how he known, how will he use this?
this is the example program
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LB_GETTEXTLEN = &H18A
Const LB_GETTEXT = &H189
Const LB_GETCOUNT = &H18B
Private Function GetListItems(ByVal hList As Long) As Variant
Dim i As Long, nCount As Long, lItemLength As Long
Dim sItem() As String
nCount = SendMessage(hList, LB_GETCOUNT, 0, ByVal 0&)
For i = 0 To nCount - 1
lItemLength = SendMessage(hList, LB_GETTEXTLEN, i, ByVal 0&)
ReDim Preserve sItem(i)
sItem(i) = String(lItemLength, 0)
Call SendMessage(hList, LB_GETTEXT, i, ByVal sItem(i))
Next i
GetListItems = sItem
End Function
there are many such examples in all different languages but concept will be the same. so i want to learn it. what does it mean and how to use it.
another example from ahk
Gui,2:+hwndhwnd
hwnd(2,hwnd)
Those are all window messages that you can find information about on the MSDN Documentation by googling them. See below links:
LB_GETTEXTLEN
LB_GETTEXT
LB_GETCOUNT
You can find them and other related messages by checking the documentation for the native List Box control.
As for the numbers they're hexadecimal numbers which are (usually) mentioned in the documentation. But since these aren't you'll have to google them and check other websites/forums, or find their values on your own by experimenting with them in C or C++ .
In VB hexadecimal numbers are represented by prepending the number with &H, whereas in C, C++, C# or alike they're prepended with 0x.
In a forms editor each window/control has a hwnd property. For windows not created by your forms package you use the API calls FindWindow (easiest but not reliable) or EnumWindows. Also GetForegroundWindow and GetDesktopWindow.
To find out the value of constants you download the C header files as part of the Windows SDK https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk. It also has the documentation for all these API calls. This is online documentation listing all the windows' functions https://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx.

VB6 sidebar app

All.
I'm attempting to develop a 'sidebar' application with vb6, which I want to behave like windows Vista's gadget sidebar or Google Desktop sidebar, in the respect that other windows could not maximize over it.
I'm aware that chances of this happening are probably very little, but I'm asking just in case.
Currently, I've got a form that has multiple controls, and runs a function on load which makes itself the exact height of the screen, minus the taskbar, and it's 'left' location is set by a timer to be 'screen.width - me.width', so it will start at full height on the far right of the screen, and cannot be moved. Code for the height is as follows, if it is necessary.
Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" ( _
ByVal hwnd As Long, _
ByVal crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Public Const GWL_STYLE = (-16)
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const LWA_COLORKEY = &H1
Public Const LWA_ALPHA = &H2
Private Const ABM_GETTASKBARPOS = &H5
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type APPBARDATA
cbSize As Long
hwnd As Long
uCallbackMessage As Long
uEdge As Long
rc As RECT
lParam As Long
End Type
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long
Function Fixheight()
Dim ABD As APPBARDATA
SHAppBarMessage ABM_GETTASKBARPOS, ABD
Form1.Height = Screen.Height - ((ABD.rc.Bottom - ABD.rc.Top) * 12)
If Form1.Height <= 600 Then
Form1.Height = Screen.Height
End If
End Function
To be clear, I do not want an 'always on top' function. I already have that, and it's driving me insane, as the form has to me closed or minimized in order to maximize, minimize of close another program (i.e. chrome, word, etc) behind it. This form must instead not allow other programs to maximize over it, so that if for example, the user maximized Chrome, chrome would maximize minus form1.width.
I doubt that this is possible because as far as I'm concerned, that would mean taking control of chrome, and essentially making it's maximize function as
me.height = screen.height - ((ABD.rc.Bottom - ABD.rc.Top) * 12)
me.width = screen.width - form1.width
which isn't possible.
Anyway, hopefully someone out there can help. As I said, I seriously doubt the possibility of having this work, but if so, all the better.
Thanks in advance!
Thanks to Ken White, I googled SHAppBarMessage and found the following website, offering a downloadable source with the very feature I needed. I just have to implement it now!!
Very glad I asked! Thank you!
Edit: Found this spanish website, which while needed some help from Google Translate, is more suited to my needs. Just need to figure out how to make it work on the Right Hand Side! Thanks again!

vb6 implementation for icmpsendecho2

I'm trying to implement a Ping program in vb6 which works for both IPv4 & IPv6 addresses. The IPv4 implementation uses IcmpSendEcho which is working fine, but the IPv6 implementation uses Icmp6SendEcho2 and I'm having a lot of difficulty getting it to work.
The function call works fine and it does not error out but the return value is always 0, and GetLastError returns 0 indicating that no errors occurred
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366041(v=vs.85).aspx
The process I follow is as follows:
Load the windows sockets dll by calling WSAStartup
Open a port handle via a call to Icmp6CreateHandle
Send a ICMP ECHO message via a call to Icmp6SendEcho2 and analyze the response
close the port handle by calling IcmpCloseHandle
Unload dll by calling WSACleanup
The definition of Icmp6SendEcho2 is as follows
Private Declare Function Icmp6SendEcho2 Lib "Iphlpapi.dll" _
(ByVal IcmpHandle As Long, _
ByVal EventtoRaise As Long, _
ByVal ApcRoutine As Long, _
ByVal ApcContext As Long, _
ByVal SourceAddressPointer As Long, _
ByVal DestinationAddressPointer As Long, _
ByVal RequestData As String, _
ByVal RequestSize As Long, _
ByVal RequestOptions As Long, _
ReplyBuffer As ICMPV6_ECHO_REPLY, _
ByVal ReplySize As Long, _
ByVal timeOut As Long) As Long
Where ICMPV6_ECHO_REPLY is defined as follows
Private Type ICMPV6_ECHO_REPLY
Address As IPV6_ADDRESS
Status As Long
RoundTripTime As Long
End Type
Private Type IPV6_ADDRESS
sin6_port As Integer
sin6_flowinfo As Long
sin6_addr(1 To 8) As Integer
sin6_scope_id As Long
End Type
The call to Icmp6SendEcho2 is made as follows
lPingResponse = Icmp6SendEcho2(lPortHandle, 0, 0, 0, VarPtr(SourceAddress), VarPtr(DestinationAddress), sMessage, Len(sMessage), 0, Reply, Len(Reply), timeOut)
I used the following link for implementing Ping for IPv4
https://support.microsoft.com/en-us/kb/300197
Any help would be awesome
Nish
The issue was associated with there not being a sufficient buffer to get the response. Changing the response structure to something like this did the trick
Private Type ICMPV6_ECHO_REPLY
Address As IPV6_ADDRESS
Status As Long
RoundTripTime As Long
data(0 To 1023) As Byte
End Type

how to convert int to float in VB6

I am trying to convert a pair of integers into a floating point variable (they should translate in a float value). I succesfully converted the pair of integers into a Long and i assumed that I was homefree by using the CDbl function. Unfortunately I am just getting the same number in the Double variable. The Long has a number like 1141187758 and this should translate in something like 530.xxx as a float. Anybody who can help me with this?
Air code
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef Destination As Any, _
ByRef Source As Any, _
ByVal Length As Long)
Function LongToFloat(ByVal l As Long) as Single
Dim f As Single
CopyMemory f, l, LenB(l)
LongToFloat = f
End Function
Adapted from this answer

Set global hotkey with Windows modifier

I want to set up a global hotkey* in VB6 that listens to the keyboard shortcut Win + O.
I have found heaps of messy examples, but nothing which involves the Windows key.
What's the ideal way to setup hotkeys and how does one include the Windows key as a modifier?
* I'm after a global shortcut. That means I don't have to have the application in focus for it to work.
RegisterHotKey in the Windows API will allow you to register a global hot key. You will also need to use GlobalAddAtom to obtain a unique hot key identifier. See this link for details.
Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Private Const WM_HOTKEY As Long = &H312
Private Const MOD_WIN As Long = &H8
m_lHotkey = GlobalAddAtom("MyHotkey")
Call RegisterHotKey(Me.hwnd, m_lHotkey, MOD_WIN, vbKeyO)
Then you just need to listen for the WM_HOTKEY message on your window.

Resources