Archive: Confused about calling wininet


Confused about calling wininet
I'm trying to call perl scripts on a server using wininet. I can run this code from

The function below runs from inside VBA; what I'd like to do is craft an NSIS version of it. I know I can call System::wininet, but i'm new to NSIS and struggling to understand how to pass parameters and get results for specific inet functions. Specifically, how to emulate the calls to InternetOpen and InternetOpenUrl below. Any pointers appreciated

-----
Function GetServerScriptResponse(sUrl As String) As String
Dim s As String
Dim hOpen As Long
Dim hOpenUrl As Long
Dim bDoLoop As Boolean
Dim bRet As Boolean
Dim sReadBuffer As String * 2048
Dim lNumberOfBytesRead As Long

hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)

bDoLoop = True
While bDoLoop
sReadBuffer = vbNullString
bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
s = s & Left$(sReadBuffer, lNumberOfBytesRead)
If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
Wend

If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
If hOpen <> 0 Then InternetCloseHandle (hOpen)
GetServerScriptResponse = s
End Function
-----

Here are the declarations it uses:
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3

Private Const scUserAgent = "VB OpenUrl"
Private Const INTERNET_FLAG_RELOAD = &H80000000

Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" _
(ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, _
ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long

Public Declare Function InternetReadFile Lib "wininet.dll" _
(ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer

Public Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer


You can also use 100% wininet.dll based http://nsis.sourceforge.net/Inetc_plug-in plug-in. Just put inetc.dll to your C:\Program Files\NSIS\plugins folder and compile sample for the beginning.


still confused
I saw inet::get and inet::put but it looked to me like those were for posting to a form and getting back from a form (and i'm a bit ignorant about these things). From your response, i'm guessing that i can call my perl script with get for functionality equivalent to calling InternetOpen and then reading the results.

I'll give it a try tonite. Thanks

G


You should call it from NSIS installation script (like this is done in inetc examples), not from perl. Plug-in puts server reply to local file (last parameter), but you can use text handling macros to handle this file directly from NSIS script as well.


Thanks
Thanks so much! I called a script and got back the expected response, which puts me well on my way to implementing my registration handler in my first NSIS script. Way easier than i thought it would be, and thanks again for your help.

- G