Hi all,
i tried to get data from a Webserver with wininet.dll using the following pseudo-code:
But i don't get any data in the buffer, InternetReadFile returns zero.
I searched MSDN but didn't find anything. The code is a try of porting it to asm from VB.
Hope you can help me.
greetings, Phueghy
i tried to get data from a Webserver with wininet.dll using the following pseudo-code:
Allocate memory for buffer (GlobalAlloc)
InternetOpen
InternetOpenUrl
InternetReadFile
Close the handles
But i don't get any data in the buffer, InternetReadFile returns zero.
I searched MSDN but didn't find anything. The code is a try of porting it to asm from VB.
Hope you can help me.
greetings, Phueghy
Try something like this
This worked for me. I believe you are passing a handle where it is expecting the address of memory.
Hopefully this works for you,
gorshing
.386
.model flat, stdcall
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\wininet.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\wininet.lib
includelib \masm32\lib\kernel32.lib
.data
url db "http://www.gmx.de",0
useragent db "wininet_test",0
hresult dd 0
hopen HANDLE ?
hfile HANDLE ?
.data?
szStuff db 500 dup(?)
.code
start:
invoke InternetOpen, ADDR useragent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0
mov hopen, eax
invoke InternetOpenUrl, hopen, ADDR url, NULL, 0, INTERNET_FLAG_RELOAD, 0
mov hfile, eax
invoke InternetReadFile, hfile, offset szStuff, 500, offset hresult
invoke InternetCloseHandle, hfile
invoke InternetCloseHandle, hopen
invoke MessageBox, NULL, offset szStuff, ADDR url, MB_OK
invoke ExitProcess, 0
end start
This worked for me. I believe you are passing a handle where it is expecting the address of memory.
Hopefully this works for you,
gorshing
thx gorshing, that worked well.
But can't i access any allocated memory as a buffer? I tried with several types of memory and as i understand it, allocating mem with GPTR which is GMEM_FIXED combined with GMEM_ZEROINIT should return a pointer to that mem, which i should be able to use in the call to InternetReadFile. But it does not work. The reason is, i want to be able to read in a large buffer without the need of having that buffer in my data section.
You see my problem?
But can't i access any allocated memory as a buffer? I tried with several types of memory and as i understand it, allocating mem with GPTR which is GMEM_FIXED combined with GMEM_ZEROINIT should return a pointer to that mem, which i should be able to use in the call to InternetReadFile. But it does not work. The reason is, i want to be able to read in a large buffer without the need of having that buffer in my data section.
You see my problem?
GlobalAlloc with GPTR should work just as you describe. Post a small bit of code with the problem. :)
this is what i use:
hope you can help :)
.386
.model flat, stdcall
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\wininet.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\wininet.lib
includelib \masm32\lib\kernel32.lib
.data
url db "http://www.gmx.de",0
useragent db "wininet_test",0
hresult dd 0
hopen HANDLE ?
hfile HANDLE ?
hmem DD ?
.code
start:
invoke GlobalAlloc, GPTR, 500
mov hmem, eax
invoke InternetOpen, ADDR useragent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0
mov hopen, eax
invoke InternetOpenUrl, hopen, ADDR url, NULL, 0, INTERNET_FLAG_RELOAD, 0
mov hfile, eax
invoke InternetReadFile, hfile, hmem, 500, hresult
invoke InternetCloseHandle, hfile
invoke InternetCloseHandle, hopen
invoke MessageBox, NULL, hmem, ADDR url, MB_OK
invoke GlobalFree, hmem
invoke ExitProcess, 0
end start
hope you can help :)
Heh, I don't know .... InternetReadFile returns FALSE, GetLastError returned 87 == ERROR_INVALID_PARAMETER, MSDN says "The parameter is incorrect."
I'm trying to figure out what's wrong with the parameters.
The memory location returned by GlobalAlloc, it's ok to pass it like it is correct? We don't need to do the offset/addr on the variable correct? That's the only thing I can see.
Ohhh, it's your result variable!! You have
It needs to be
On MSDN
Hope this helps man,
gorshing
I'm trying to figure out what's wrong with the parameters.
The memory location returned by GlobalAlloc, it's ok to pass it like it is correct? We don't need to do the offset/addr on the variable correct? That's the only thing I can see.
Ohhh, it's your result variable!! You have
invoke InternetReadFile, hfile, hmem, 500, hresult
It needs to be
invoke InternetReadFile, hfile, hmem, 500, offset hresult
On MSDN
BOOL WINAPI InternetReadFile(
IN HINTERNET hFile,
IN LPVOID lpBuffer,
IN DWORD dwNumberOfBytesToRead,
OUT LPDWORD lpdwNumberOfBytesRead
);
Hope this helps man,
gorshing
gorshing thank you very much that did the trick.
i was already going crazy, browsing MSDN and finding nothing (or better: overlooking the important part.)
It's always those little things, that make you mad.
Thanks again! :alright:
i was already going crazy, browsing MSDN and finding nothing (or better: overlooking the important part.)
It's always those little things, that make you mad.
Thanks again! :alright: