Win32 Api

Windows specific forum
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Win32 Api

Post by reisve »

Hi
There is a function in the advapi32.dll/lib for Windows Vista I would like to use in an aplication I'm developing. PureBasic has a library called advapi32.lib, but the function is not there (old DLL/LIB???).

How can I get a new version of that lib (converting from DLL? How?)
Is there any simple but good tutorial on how to use APIs in general in PureBasic?

Thank You
User avatar
Sveinung
Enthusiast
Enthusiast
Posts: 142
Joined: Tue Oct 07, 2003 11:03 am
Location: Bergen, Norway

Post by Sveinung »

Here is something on winapi http://www.purebasic.fr/english/viewtopic.php?t=10046

Regards
Sveinung
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

You can open the .dll file directly and use the functions like this:

Code: Select all

Lib = OpenLibrary(0, "The_DLL_That_Contains_The_Function.dll")

  If Lib
    hs = CallFunction(@Lib,"API_Function_Name", <Func_Param>, <Func_Param>, <Func_Param>, etc...)
  EndIf
CloseLibrary(Lib)
and if your going to use the memory locations of the functions instead of calling them directly you do something like this :


Code: Select all

Lib_MyFunc = LoadLibrary_("Some_Dll.dll")

  If LibTNP
  *pLib_MyFunc_1 = GetProcAddress_(Lib_MyFunc, "Function_I_Want_to_use_1")
  *pLib_MyFunc_2 = GetProcAddress_(Lib_MyFunc, "Function_I_Want_to_use_2")
  ;*pLib_MyFunc_3
  ;*pLib_MyFunc_4
  ;*pLib_MyFunc_5
  ; etc....
    
  h_func_1 = CallFunctionFast(*pLib_MyFunc_1, <Param>, <Param>, <Param>, etc.....)
  h_func_2 = CallFunctionFast(*pLib_MyFunc_2, <Param>, <Param>, <Param>, etc.....)
       
;     h_func_3 = CallFunctionFast(*pLib_MyFunc_3, <Param>, <Param>, <Param>, etc.....)
    
;     h_func_4 = CallFunctionFast(*pLib_MyFunc_4, <Param>, <Param>, <Param>, etc.....)
     
;     h_func_5 = CallFunctionFast(*pLib_MyFunc_5, <Param>, <Param>, <Param>, etc.....)
    
;     etc.....

  EndIf
  
  FreeLibrary_(Lib_MyFunc)
LoadLibrary_ and FreeLibrary_ can be replaced with Pure Basic functions.

And....of course as you have discovered, if PB has a library that contains the function you just do a SomeAPIFunction_ with the _ after the function name.

OK, I think I got this about right.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Post by reisve »

Thank You all

I found the suvival guide which have a good tutorial not only in APIs, but overall Pure Basic.

However a question remain. How do I convert a .DLL to a Lib to be used in PB? Is that possible?

As I said, there is an advapi32.lib in PB, with contains the functions of the advapi32.dll functions, but a new version of that DLL is out. How can I use it as a LIB in PB...
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

type this into cmd.exe
"C:\Program Files\PureBasic4.30\Compilers\polib.exe" /out:advapi32.lib c:\windows\system32\advapi32.dll
change to the source's directory, and substitute the path to your PB dir.
Then do an Import "advapi32.lib" in your code, and add the function in there. (i.e. convert the types from MSDN or similar)


And if I recall correctly, PB's *.lib files contain only functions that work on all versions of windows (that are supported)

Just remember that if this function is Vista only, the user will get an unfriendly message if they start the exe on XP or earlier.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Post by reisve »

the lib is in
c:\program files\purebasic\purelibraries\windows\libraries\advapi32.lib

the new advapi32.dll/lib is for all OS versions but have new functions specific to Vista
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

And when you do this the messges your going to receive are:

Code: Select all

C:\Windows\system32>"C:\Program Files\PureBasic\Compilers\polib.exe" /out:advapi32.lib c:\windows\system32\advapi32.dll
POLIB: warning: Symbol 'A_SHAFinal' is forwarded to 'NTDLL.A_SHAFinal'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'A_SHAInit' is forwarded to 'NTDLL.A_SHAInit'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'A_SHAUpdate' is forwarded to 'NTDLL.A_SHAUpdate'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'CreateTraceInstanceId' is forwarded to 'ntdll.EtwCreateTraceInstanceId'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventActivityIdControl' is forwarded to 'ntdll.EtwEventActivityIdControl'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventEnabled' is forwarded to 'ntdll.EtwEventEnabled'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventProviderEnabled' is forwarded to 'ntdll.EtwEventProviderEnabled'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventRegister' is forwarded to 'ntdll.EtwEventRegister'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventUnregister' is forwarded to 'ntdll.EtwEventUnregister'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventWrite' is forwarded to 'ntdll.EtwEventWrite'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventWriteEndScenario' is forwarded to 'ntdll.EtwEventWriteEndScenario'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventWriteStartScenario' is forwarded to 'ntdll.EtwEventWriteStartScenario'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventWriteString' is forwarded to 'ntdll.EtwEventWriteString'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'EventWriteTransfer' is forwarded to 'ntdll.EtwEventWriteTransfer'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'GetTraceEnableFlags' is forwarded to 'ntdll.EtwGetTraceEnableFlags'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'GetTraceEnableLevel' is forwarded to 'ntdll.EtwGetTraceEnableLevel'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'GetTraceLoggerHandle' is forwarded to 'ntdll.EtwGetTraceLoggerHandle'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'MD4Final' is forwarded to 'NTDLL.MD4Final'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'MD4Init' is forwarded to 'NTDLL.MD4Init'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'MD4Update' is forwarded to 'NTDLL.MD4Update'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'MD5Final' is forwarded to 'NTDLL.MD5Final'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'MD5Init' is forwarded to 'NTDLL.MD5Init'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'MD5Update' is forwarded to 'NTDLL.MD5Update'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'RegisterTraceGuidsA' is forwarded to 'ntdll.EtwRegisterTraceGuidsA'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'RegisterTraceGuidsW' is forwarded to 'ntdll.EtwRegisterTraceGuidsW'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'TraceEvent' is forwarded to 'ntdll.EtwLogTraceEvent'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'TraceEventInstance' is forwarded to 'ntdll.EtwTraceEventInstance'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'TraceMessage' is forwarded to 'ntdll.EtwTraceMessage'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'TraceMessageVa' is forwarded to 'ntdll.EtwTraceMessageVa'; assuming it's a function.
(The forwarding information will not be saved).
POLIB: warning: Symbol 'UnregisterTraceGuids' is forwarded to 'ntdll.EtwUnregisterTraceGuids'; assuming it's a function.
(The forwarding information will not be saved).
don't be alarmed.

And, if you get the latest Driver Development Kit from Microsoft you can also get the latest advapi32.lib for Vista in the kit.
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Post by reisve »

This seems to be great. But...
I followed your instructions and the advapi32.lib was created and I could see the function I'm looking for in there. Now... I renamed the old lib and run a piece of code I know use functions from there. The code still run :shock:
Where does PB goes to get the API functions?
Post Reply