wsastartup_ vs. wsastartup

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

wsastartup_ vs. wsastartup

Post by blueznl »

(i guess something got lost from the 'newbies read this faq'... or i'm not bright enough to figure it out myself...)

gfa:

ws_wsastartup% = GetProcAddress(ws_winsock_h&,"WSACleanup")
ws_retval& = P:(ws_wsastartup%)($0101,L:V:ws_wsadata$)

pure:

*ws_wsastartup = IsFunction(ws_winsock_pb,"WSAStartup")
ws_retval = CallFunctionFast(*ws_wsastartup,$101,ws_wsadata.s)

in pure, i found out (by browsing this forum :-)) that i can use:

ws_retval = WSAStartUp_($101,@ws_wsadata.s)

but uhm...

where did that underscore come from? (i assume it was added so it would not interfere with includes of 'official' files, but i just might b wrong... this would mean there must be a whole list of api calls included somewhere in some file)

am i correct or is my mind pulling another trick on me?

(yeah i know i shouldn't use a string in the samples above, it's just a quick placeholder)
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Yes, most (not all) of the API calls is already easily accessible in PB by just adding an underscore character('_') to the API call name of interest.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

thanks, pupil, got another question for you.. does purebasic automatically open the corresponding ddl?

i was assuming i should always open a dll before using it, such as

x_number()
ws_winsock_pb = x_number
ws_winsock_h = OpenLibrary(x_number,"WSOCK32.DLL")

but if i don't, it looks like there are still no problems when i call wsastartup... euh? (puzzled look)
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

blueznl wrote:.. does purebasic automatically open the corresponding ddl?
Yes, PB does this for you.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

hmmm... that brings me to the next question (full of questions lately):

in the api descriptions, parameters for calls to certain functions have a specified length, word, long etc., for example wsastartup_

int WSAStartup( WORD wVersionRequested, LPWSADATA lpWSAData );

when i was using gfabasic i had to make sure that all parameters were the right type

when i look at the code samples i have seen thus far, i noticed that there is no type forcing, is pure handling type checking and / or conversion all in the background?

ws_retval = WSAStartUp_($101,@ws_wsadata)

ws_retval = CallFunctionFast(*ws_wsastartup,$101,ws_wsadata.s)

if so, does it do that for all api's, or only for those it knows?
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

For Windows API calls, PB only checks the number of parameters,
everything else is the programmer's work.

Timo
quidquid Latine dictum sit altum videtur
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

shouldn't the program crash on this then?

ws_retval = WSAStartUp_($101,@ws_wsadata)

i mean, the first parameter should be a word, the second a pointer... how does the $101 become a word?

i'm getting more and more puzzled, something big and obvious must be escaping me...

perhaps i should be more specific:

a dll has a function xyz with two parameters, one word, one long

so i guess it should be called with:

xyz( a.w , b.l )

but what happens if i call it with

xyz( b.l , a.w )

or, what if i use numbers instead of variables

xyz ( $1 , $2 )

one day i am going to understand this...
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

freak wrote:For Windows API calls, PB only checks the number of parameters,
everything else is the programmer's work.

Timo
there's your answer :wink: --jb
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

it's a good answer :D unfortunately there's a little more :(

> For Windows API calls, PB only checks the number of
> parameters, everything else is the programmer's work.

assume a function xyz exists which takes two parameters, one word and one long

then how do you force types during the call?

the following makes sense:

xyz ( a.w , b.l )

but what will happen if i do:

xyz ( $101 , $101 )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

the whole question / this whole thread might be moot and caused by a misunderstandig on my side...

i started programming windows stuff using gfabasic 16 bits, where type declaration was essential...

on the irc it was suggested that all parameters in calls to win32 functions are in longs anyway, well, if that is the case it doesn't matter, and there is no need for type forcing

it would also mean that the parameters specified in win32help don't mean much when it comes to function calls... oh well, another day, another lesson, and when i'm wrong someone will hopefully correct me...
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I think, the API calls, are all called with 32 bit values, even if the parameter
of the function actually expects a word for example. (Maybe that's part of
the stdcall, i don't know exactly)

The truth is, the stuff works fine, even if you use a direct number like $101,
so you don't have to worry about a thing here.

You should still try using the expected variable type for a WinAPI call, just
to be sure, and to keep clear, what the function expects, in order to avoid
mistakes.
Maybe this one can be a help here:
http://www.reelmediaproductions.com/pb/ ... ntypes.txt

Timo
quidquid Latine dictum sit altum videtur
Post Reply