Passing different pointer types warning

General FreeBASIC programming questions.
Post Reply
Julcar
Posts: 141
Joined: Oct 19, 2010 18:52
Contact:

Passing different pointer types warning

Post by Julcar »

Hello guys,

I've manually ported some WinHTTP interfaces into a FreeBasic .bi file, which can be found here
Also created a http client module and his .bi file

Now this code:

Code: Select all

#INCLUDE "libs/http-client.bi"
DIM AS STRING Content, RequestUrl
RequestUrl = COMMAND(1)
HTTP_Open("GET", RequestUrl)
HTTP_Send()
Content = HTTP_GetResponse()
HTTP_Clean()
IF Content <> "" THEN
  Print Content
ELSE
  Print LastError
END IF

Code: Select all

fbc -x .\test.exe -l winhttp test.bas libs/http-client.bas
But displays these warnings:

Code: Select all

libs\http-client.bas(119) warning 3(1): Passing different pointer types, at parameter 4 of WINHTTPSENDREQUEST()
libs\http-client.bas(159) warning 3(1): Passing different pointer types, at parameter 2 of WINHTTPREADDATA()
I would like if somebody can explain me what means those warnings.

Regards.
SARG
Posts: 1766
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Passing different pointer types warning

Post by SARG »

In both cases the procedures are expecting LPVOID type so you just need to cast the parameters.

Like that :
cast(LPVOID,VarPtr(RequestData))
cast(LPVOID,VarPtr(ResponseLen(0)))
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Passing different pointer types warning

Post by MrSwiss »

Alternative:
instead of LPVOID, you can also use the FB equivalent: Any Ptr ...
and, instead of cast() use: CPtr() (to make it more FB 'look alike')

CPtr( Any Ptr, VarPtr(whatever_variable) )
or (simpler IMO):
CPtr( Any Ptr, @whatever_variable )
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Passing different pointer types warning

Post by MrSwiss »

What I've forgotten to mention, there is one exception:
if the variable is a String, then StrPtr(string_var) is mandatory.

CPtr( Any Ptr, StrPtr(string_var) )
Julcar
Posts: 141
Joined: Oct 19, 2010 18:52
Contact:

Re: Passing different pointer types warning

Post by Julcar »

MrSwiss wrote:What I've forgotten to mention, there is one exception:
if the variable is a String, then StrPtr(string_var) is mandatory.

CPtr( Any Ptr, StrPtr(string_var) )
I found it here: http://www.jose.it-berater.org/winhttp/ ... eaders.htm
This allows me to replace AS WSTRING PTR to AS ZSTRING PTR and thus can accept the output of STRPTR, without having to convert the pointer type (honestly, I HATE the "Any" keyword)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Passing different pointer types warning

Post by MrSwiss »

@Julcar, why don't you get the documentation from it's source (manufacturer)?

See here for: WinHttpQueryHeaders()
There is also (seems to be more current): WinHttpQueryHeadersEx()
Looks to me, that they both require WString Ptr, aka: StrPtr(WString).

Btw: don't understand what's apparently wrong with Any (Keyword)? Just one, among many more ...
Julcar
Posts: 141
Joined: Oct 19, 2010 18:52
Contact:

Re: Passing different pointer types warning

Post by Julcar »

MrSwiss wrote:@Julcar, why don't you get the documentation from it's source (manufacturer)?

See here for: WinHttpQueryHeaders()
There is also (seems to be more current): WinHttpQueryHeadersEx()
Looks to me, that they both require WString Ptr, aka: StrPtr(WString).

Btw: don't understand what's apparently wrong with Any (Keyword)? Just one, among many more ...
I've seen the msdn link every 5 minutes last days hehe
You are right, it returns wide string to the buffer, but after all there are just ascii chars + null, which are easily trimmed and what I have now is common zstrings

About the "Any" keyword... I would not like to enter in such discussion here, but all I can say is that the Any type makes some things very ambigous
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Passing different pointer types warning

Post by MrSwiss »

Julcar wrote:... but after all there are just ascii chars + null, ...
While this is true for english, it may be very different for other languages, especially if
they're using different alphabet's: cyrillic, arab, hebrew, chinese, japanese, thai e.t.c.
Post Reply