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.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa383917(v=vs.85).aspx

typedef void ( CALLBACK *WINHTTP_STATUS_CALLBACK)(
_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

http://msdn.microsoft.com/en-us/library/windows/desktop/aa384115(v=vs.85).aspx

WINHTTP_STATUS_CALLBACK WINAPI 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,
                                           (WINHTTP_STATUS_CALLBACK)AsyncCallback,
                                           WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS,
                                           NULL);

How do I define a pointer to the AsyncCallback function in vb6?
Module1.bas
RuuuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
use the AddressOf() function
0
RuuuAuthor Commented:
I have used that function but in the asynccallback function parametert because of  ipvstatusinformation module is crashing.what should i used instead of long.?
0
aikimarkCommented:
Your declaration needs to be changed.  The Integer parameters should be Long.
http://msdn.microsoft.com/en-us/library/cc230318.aspx
Public Declare Function WINHTTP_STATUS_CALLBACK Lib "winhttp.dll"
(ByVal hSession As Long, dwContext As Long, dwInternetStatus As Long,
lpvStatusInformation As Long, dwStatusInformationLength As Long)

Open in new window

However, these two parameters may not be able to be handled as you might see in the C code, since VB Long Integer data types are signed and these parameters are treating it as unsigned.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

RuuuAuthor Commented:
Thank you so much
0
RuuuAuthor Commented:
Can anyone check if the code in the module is written correct or not?
0
RuuuAuthor Commented:
As it is crashing at winhttpreceiveresponse fumction.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.