AutoHotkey Community

It is currently May 27th, 2012, 10:01 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: June 21st, 2008, 10:15 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
I'm trying to POST by using WinINet.
but i stucked at calling HttpOpenRequestA.
I get 87 of A_LastError which means ERROR_INVALID_PARAMETER
even if i put 0 for last 5 parameters of HttpOpenRequestA, it returns 122 of A_LastEror which means ERROR_INSUFFICIENT_BUFFER
anyone have idea for it?

Thanks for reading.
My attempt is below

Code:
hModule := DllCall("LoadLibrary", "Str", "WinInet.Dll")

;---------------------------------------------------------------
Agent := "AutoHotkey"

hInternet := DllCall("WinINet\InternetOpenA"
                    , "Str*", Agent
                    , "Int" , 4
                    , "Str*", 0
                    , "Str*", 0
                    , "Uint", 0)

;Working
MsgBox % hInternet " / " ErrorLevel " / " A_LastError
;---------------------------------------------------------------
ServerName := "www.autohotkey.com/forum"

hConnect := DllCall("WinINet\InternetConnectA"
                    , "uInt", hInternet
                    , "Str*", ServerName
                    , "Int" , 80 ;INTERNET_DEFAULT_HTTP_PORT
                    , "Str*", 0 ;UserName
                    , "Str*", 0 ;Password
                    , "uInt", 3 ;INTERNET_SERVICE_HTTP
                    , "uInt", 0
                    , "uInt*", 0)   

;Working
MsgBox % hConnect " / " ErrorLevel " / " A_LastError           
;---------------------------------------------------------------
HTTPVerb := "POST"
ObjectName := "search.php"
Version := ""
Referer := ""
AcceptTypes := ""
Flags := ""
Context := ""

hRequest := DllCall("WinINet\HttpOpenRequestA"
                    , "uInt", hConnect
                    , "Str*", HTTPVerb
                    , "Str*", ObjectName
                    , "Str*" , Version ;Version
                    , "Str*" , Referer ;Referer
                    , "Str*" , AcceptTypes ;AcceptTypes
                    , "uInt" , Flags ;Flags
                    , "uInt*" , Context ) ;Context

;Not Working with A_LastError 87 (ERROR_INVALID_PARAMETER)
MsgBox % hRequest " / " ErrorLevel " / " A_LastError
;---------------------------------------------------------------

DllCall("WinINet\InternetCloseHandle", "uInt", hInternet)       
DllCall("FreeLibrary", "UInt", hModule)

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2008, 5:55 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
You can safely assume that you got it wrong if you had to use Str* that many times. I suggest to replace all Str* with Str.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 8:50 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
Sean wrote:
You can safely assume that you got it wrong if you had to use Str* that many times. I suggest to replace all Str* with Str.
Thanks for answer Sean.
removing * from types solved the problem. though i still don't get that why it's working even that WinAPI function requires LPCSTR.
i thought like i needed * everywhere when WinAPI function requires pointer in types

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2008, 2:21 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
AHK's str is a pointer already.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher, specter333, tomoe_uehara, XstatyK and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group