Avatar of Ruuu
Ruuu asked on

Wnat to implement Asynchronous winhttp in vb6

I have a vb6 service which uses Synchronous WinHttp calls to a remote server. These calls lockup the service during times when there appears to be connection issues (network/Internet etc).

My task is to implement WinHttp Asynchronous calls.

First step, I'm trying to figure out the conversions from C++ to vb6. Bearing in mind I've never written a line of C++ before.


_In_  HINTERNET hInternet,
_In_  DWORD_PTR dwContext,
_In_  DWORD dwInternetStatus,
_In_  LPVOID lpvStatusInformation,
_In_  DWORD dwStatusInformationLength

This is my attempt:

Public Declare Function WINHTTP_STATUS_CALLBACK Lib "winhttp.dll"
(ByVal hSession As Long, dwContext As Long, dwInternetStatus As Integer,
lpvStatusInformation As Long, dwStatusInformationLength As Integer)

I have no idea if that's correct and unfortunately I can't test it until I get a bit further.

The next one is WinHttpSetStatusCallback


_In_        HINTERNET hInternet,
_In_        WINHTTP_STATUS_CALLBACK lpfnInternetCallback,
_In_        DWORD dwNotificationFlags,
_Reserved_  DWORD_PTR dwReserved

This is my attempt:

Public Declare Function WinHttpSetStatusCallback Lib "winhttp.dll"
(ByVal hInternet As Long, ByVal lpfnInternetCallback As Long,
ByVal dwNotificationFlags As Long, ByVal dwReserved As Long) As Long

I don't really know if my conversions are correct. Can anyone verify this?

Next, I don't know how to implement WinHttpSetStatusCallback - for example I don't know if I have the pointer to the Callback function correct.

_In_        WINHTTP_STATUS_CALLBACK lpfnInternetCallback,

converted to:

ByVal lpfnInternetCallback As Long

I'm not sure if I have that correct either.

I don't have a clear idea on how to define the Async Callback function itself. Here is my initial attempt:

Public Function AsyncCallback(
                        ByVal hInternet As Long,
                        dwContext As Long,
                        dwInternetStatus As Long,
                        lpvStatusInformation As Long,
                        dwStatusInformationLength As Long)
    //code in here
End Function

Then finally, wiring it all up is going to be interesting. But first I have to make sure I have the foundations right, otherwise I can't expect it to magically "work".

The MSDN C++ example is as follows: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384115(v=vs.85).aspx

// Install the status callback function.
WINHTTP_STATUS_CALLBACK isCallback = WinHttpSetStatusCallback( hSession,

How do I define a pointer to the AsyncCallback function in vb6?
Visual Basic Classic

Avatar of undefined
Last Comment

8/22/2022 - Mon

use the AddressOf() function

I have used that function but in the asynccallback function parametert because of  ipvstatusinformation module is crashing.what should i used instead of long.?

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thank you so much
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

Can anyone check if the code in the module is written correct or not?

As it is crashing at winhttpreceiveresponse fumction.