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
Win32 Api
You can open the .dll file directly and use the functions like this:
and if your going to use the memory locations of the functions instead of calling them directly you do something like this :
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.
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)
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)
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.
http://www.xs4all.nl/~bluez/datatalk/pu ... napi_calls
http://www.xs4all.nl/~bluez/datatalk/pu ... i_and_dlls
http://www.xs4all.nl/~bluez/datatalk/pu ... i_and_dlls
( 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... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
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...
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

- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
type this into cmd.exe
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.
change to the source's directory, and substitute the path to your PB dir."C:\Program Files\PureBasic4.30\Compilers\polib.exe" /out:advapi32.lib c:\windows\system32\advapi32.dll
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!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
And when you do this the messges your going to receive are:
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.
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).
And, if you get the latest Driver Development Kit from Microsoft you can also get the latest advapi32.lib for Vista in the kit.


