WINInet is not returning XML value

WINInet is not returning XML value

Post by Bria » Sun, 04 Jan 2009 04:40:53

need to use the WinInet.dll to send a GET request to a server and
read the returned data. I cannot use the WebBrowser control, because
I need to run multiple copies of the program on one machine and we
have discovered that the results of a WebBrowser1.Navigate in one copy
may be picked up by the DocumentComplete event in the other program
and that just won't do!

I've used the WinInet functions in other programs with no problems,
but they all use a POST instead of a GET.

I've installed Microsoft's FIDDLER and discovered that the call to
HttpSendRequest is being processed properly and the data is being sent
back, but the InternetReadFile section is returning an empty string!
The data that is coming back is XML encoded, but I thought that I
should have seen something in the returned stream, but nothing is

Here is the section of code in question:

Public Function SC_Process(param1 As String) As String

Dim hInternetOpen As Long
Dim hInternetConnect As Long
Dim hHttpOpenRequest As Long
Dim bRet As Boolean
Dim iRetVal As Integer
Dim MyPtr As Long
Dim EndPtr As Long
Dim lpszPostData As String
Dim lPostDataLen As Long
Dim SearchURL As String
Dim i As Integer
Dim bDoLoop As Boolean
Dim sReadBuffer As String * 2048
Dim lNumberOfBytesRead As Long
Dim sBuffer As String

Dim dwTimeOut As Long
Dim sHeader As String

Const HTTP_ADDREQ_FLAG_ADD = &H20000000
'Type of service to access.

dwTimeOut = 10000 '10 second timeout.
param1 = Mid$(param1, 8)
MyPtr = InStr(1, param1, "/", vbTextCompare)
EndPtr = InStr(MyPtr, param1, "/")
SearchURL = Mid$(param1, EndPtr)
EndPtr = InStr(1, param1, "?")
lpszPostData = Mid$(param1, EndPtr + 1)

hInternetOpen = 0
hInternetConnect = 0
hHttpOpenRequest = 0

'Screen.MousePointer = vbHourglass
'Use registry access settings.
hInternetOpen = InternetOpen("http generic", _
vbNullString, _
vbNullString, _

If hInternetOpen <> 0 Then

'Change the server to your server name
hInternetConnect = InternetConnect(hInternetOpen, _
Left$(param1, MyPtr - 1), _
vbNullString, _
"HTTP/1.0", _
0, _

If hInternetConnect <> 0 Then
'Brings the data across the wire even if it locally
hHttpOpenRequest = HttpOpenRequest(hInternetConnect, _
"GET", _
SearchURL, _
"HTTP/1.0", _
vbNullString, _

1. Well Formed XML not returned using FOR XML (<?xml version="1.0"?>)

2. Help calling function from DLL and processing returned value (Can not marshal return value)

Hi again,
I'm trying to call functions from a proprietary DLL but it's turned out to
be more difficult than I thought.

I have this W32.DLL which was written in C by USPS. They don't provide the
code so I only have the documentation.
I'm trying to call a function called z4date that, according to the docs,
returns the date as "an 8-byte character string in the "YYYYMMDD" format".
When I run it with this code I've written , I get "Can not marshal return

My real concern is that, if I'm having trouble with these functions that
return simple data types, how am I going to interact with functions that
return user-defined data types?

This is what I've written in the class so far:

using System.Runtime.InteropServices;
namespace ZM7
/// <summary>
/// Summary description for AMS.
/// </summary>
public class AMS
public static extern int z4open(); //another function from the dll
[DllImport("C:\\zm7\\Developm\\DLL\\W32.DLL")] /* Do I need to use
DllImport for every fiunction I'm using? */
public static extern byte[] z4date();

public byte[] getDate()
Byte[] myDate;
myDate = new Byte[8];
myDate = z4date(); //function call where I receive error "Can not
marshal return value"
return myDate();

Any help is appreciated.

3. "not all code paths return a value" when throwing exception, can't return a value

4. Function to return a Ref Cursor from XML (NOT XML from a Ref Cursor)

5. RETURN VALUE in stored procedure not always returning to ADO

6. PDO with MS SQL Server - output parameters/return values not returned

7. Window.return is not returning a value

8. RETURN VALUE and OUTPUT PARAMETERS in stored procedure not always returning to ADO

9. Return value not returning correctly when I add an Insert Statement

10. How to check the Xml value is or not conform the specific xml schema?

11. md5::md5 returns unexpected value,am I using it correctly?

12. Am I right in thinking a return value is carried over into a __finally statement?

13. B changing the XML node value only in memory not in the XML doc

14. 'Lost' function return value: what am I doing wrong?

15. windows program return values vs perl return values from a call to system() -- windows post only