Page 1 of 1

Confusion Calling DLLs vs Calling Win32

Posted: Sun Nov 18, 2007 4:15 am
by JElliott
Be gentle with me :) - this is my first PB excursion into the world of Win32 API and DLLs. I'm confused about calling the Win32 API and other DLLs. In the two examples below I'm calling two different DLLs neither of which has constants that PB recognizes - My first question is why not? Does this mean the constants (and thus the DLLs) are not part of the Win32 API?

My second question is I have to load the Winhttp.dll but not the Wininet.dll my assumption is that something else loaded the Wininet.dll? Also I can use the Func_ method to call the Wininet.dll but have to use the CallFucntion method for the Winhttp.dll.

Is there a way to call the Winhttp.dll. via the Func_ method?

Hope you can follow my ramblings and can offer some insight.

Thanks,
Jeff

Code: Select all

;Requires Winhttp.dll & Wininet.dll

#INTERNET_OPEN_TYPE_DIRECT = $1
;
#WINHTTP_ACCESS_TYPE_NO_PROXY = $1
#WINHTTP_NO_PROXY_NAME = #Null
#WINHTTP_NO_PROXY_BYPASS = #Null
#WINHTTP_FLAG_ASYNC = $10000000

Procedure doPost()
  ; Example 1 requires Winhttp.dll)
  winHTTPlib.l = OpenLibrary(#PB_Any,"Winhttp.dll")
  Debug IsLibrary(winHTTPlib)
  ;WinHttpOpenHandle.l = WinHttpOpen_("User Agent",#WINHTTP_ACCESS_TYPE_NO_PROXY,#WINHTTP_NO_PROXY_NAME.,#WINHTTP_NO_PROXY_BYPASS,#WINHTTP_FLAG_ASYNC)
  WinHttpOpenHandle.l = CallFunction(winHTTPlib,"WinHttpOpen","User Agent",#WINHTTP_ACCESS_TYPE_NO_PROXY,#WINHTTP_NO_PROXY_NAME,#WINHTTP_NO_PROXY_BYPASS,0)
  Debug WinHttpOpenHandle
  CloseLibrary(winHTTPlib) 
  ;
  ; Example 2 requires Wininet.dll
  internetOpenHandle.l = InternetOpen_("User Agent Info Goes Here",#INTERNET_OPEN_TYPE_DIRECT,"","",0)
  Debug internetOpenHandle
  InternetCloseHandle_(internetOpenHandle)
  ;
EndProcedure
doPost()

Posted: Sun Nov 18, 2007 7:47 am
by jorgejones
pb doesnt really have support to every winapi library by this i am saying that it doesnt have the headers (constants etc) defined by default for this libs but you obviously can still gather this from the api vendor and manage it on your own or add them to the pool

what is your actual prblem? src ran just fine here

Posted: Sun Nov 18, 2007 1:47 pm
by JElliott
thanks for the response -- but my problem was not an actual code problem. - perhaps I'm in the wrong place with my questions - I was trying to get answers to the specific questions in my post.

Posted: Sun Nov 18, 2007 1:58 pm
by srod
JElliott, it does seem to me that jorgejones has done a good job of answering your specific questions! He has explained that PB does not directly import every Win api library by default or indeed place the definition of every constant / structure from all of the SDk header files into it's resident files. Such an undertaking would take months!

Purebasic makes directly available a large chunk of the Win api; certainly all of the 'regular' api libraries are directly available.

Others, like Winhttp.dll have not been directly imported as yet. Now this could be an oversight, or a simple case of there not being enough hours in the day for Fred and co! The fact is that, as you've demonstrated yourself with OpenLibrary() etc. there is nothing preventing you from accessing these libraries. Although instead of OpenLibrary() I would consider using Import / EndImport.

If you feel that the Winhttp.dll library should be imported by default then make a post in the Features Request forum etc.