-
February 23rd, 2009, 07:46 AM
#1
Calling an API without the Header
well ive been looking around and i found that you can call an API using LoadLibrary() without using the header (using inline asm)
i find it very useful couze i dont need to include the "windows.h" if im just gone use the MessageBox API and makes the application small and fast
the only code i could dig up was this
Code:
__asm{
push par1
push par2
mov eax, AdressOfApi ; ret of GetProcAddress(LoadLibrary("Dll name"),"Api name")
call eax
}
GetProcAddress(LoadLibrary("Dll name"),"Api name")
how can i call a simple MessageBox through this code?
-
February 23rd, 2009, 08:58 AM
#2
Re: Calling an API without the Header
You can call any exported function in a DLL using GetProcAddress and LoadLibrary. No assembly language required. I wouldn't bother using the Windows API that way though.
-
February 23rd, 2009, 09:04 AM
#3
Re: Calling an API without the Header
This will also not compile for 64-bit
-
February 23rd, 2009, 09:05 AM
#4
Re: Calling an API without the Header
Originally Posted by Cpp_Noob
... and makes the application small and fast
How much (how many bytes) "smaller" and how many milliseconds faster do you expect to have your application using this "technique"?
Victor Nijegorodov
-
February 23rd, 2009, 09:08 AM
#5
Re: Calling an API without the Header
Originally Posted by Cpp_Noob
well ive been looking around and i found that you can call an API using LoadLibrary() without using the header (using inline asm)
i find it very useful couze i dont need to include the "windows.h" if im just gone use the MessageBox API and makes the application small and fast
the only code i could dig up was this
Code:
__asm{
push par1
push par2
mov eax, AdressOfApi ; ret of GetProcAddress(LoadLibrary("Dll name"),"Api name")
call eax
}
GetProcAddress(LoadLibrary("Dll name"),"Api name")
how can i call a simple MessageBox through this code?
An you plan to put that all over your code? What kind of application is this that you need it "small and fast"? Have you run benchmarks to see what's the difference in speed between the two approaches? I don't think you can measure anything significant.
-
February 23rd, 2009, 11:23 AM
#6
Re: Calling an API without the Header
Originally Posted by Cpp_Noob
how can i call a simple MessageBox through this code?
Even if its fatser in couple of micros ( just a guess maybe not but lets say it faster ) , what’s the benefit here if you end up showing a message box that waits for use input anyway ?
Cheers
Last edited by golanshahar; February 23rd, 2009 at 11:26 AM.
-
February 23rd, 2009, 12:22 PM
#7
Re: Calling an API without the Header
thanks for the replys
i was hoping for a simple MessageBox example so i can run some test
Originally Posted by VictorN
How much (how many bytes) "smaller" and how many milliseconds faster do you expect to have your application using this "technique"?
what if i use 5 or more headers in my app? whould that drop the app size alot?
im really interested on lightweight applications
-
February 23rd, 2009, 12:25 PM
#8
Re: Calling an API without the Header
Originally Posted by Cpp_Noob
thanks for the replys
i was hoping for a simple MessageBox example so i can run some test
what if i use 5 or more headers in my app? whould that drop the app size alot?
im really interested on lightweight applications
No. Why are you concerned about app size anyway?
-
February 23rd, 2009, 12:26 PM
#9
Re: Calling an API without the Header
Originally Posted by Cpp_Noob
what if i use 5 or more headers in my app? whould that drop the app size alot?
Define *alot*.
Originally Posted by Cpp_Noob
im really interested on lightweight applications
What "weight" would for you *light* and what not?
Victor Nijegorodov
-
February 23rd, 2009, 12:34 PM
#10
Re: Calling an API without the Header
Originally Posted by GCDEF
No. Why are you concerned about app size anyway?
not only size but speed, they go hand by hand
Originally Posted by VictorN
Define *alot*.
Well , instead of including multiple headers on the project i can call them directly with GetProcAddress() and LoadLibrary(), wouldn't that eliminate the multiple headers size added to the application? And with the asm code making the API call faster?
-
February 23rd, 2009, 12:42 PM
#11
Re: Calling an API without the Header
Originally Posted by Cpp_Noob
not only size but speed, they go hand by hand
Well , instead of including multiple headers on the project i can call them directly with GetProcAddress() and LoadLibrary(), wouldn't that eliminate the multiple headers size added to the application? And with the asm code making the API call faster?
Where did you come up with size of the exe is related to speed of the app? Adding headers to an application doesn't slow it down.
If anything that would appear to make it run slower, as the DLL would be loaded at the call instead of startup. Calling GetProcAddress at runtime instead of link time, and loading the DLL as the call is made instead of at startup will slow the app down.
-
February 23rd, 2009, 12:48 PM
#12
Re: Calling an API without the Header
well, in "theory" it looked logical to me
thanks for explaining it
-
February 23rd, 2009, 01:38 PM
#13
Re: Calling an API without the Header
The number of headers only affects compile speed, not run speed.
-
February 23rd, 2009, 03:28 PM
#14
Re: Calling an API without the Header
Originally Posted by Cpp_Noob
thanks for the replys
i was hoping for a simple MessageBox example so i can run some test
what if i use 5 or more headers in my app? whould that drop the app size alot?
im really interested on lightweight applications
Well, I already asked: what kind of app are you developing? If you have a few hundred lines application, that it might not be of much importance how you write it. But when you're developing serious, large applications, and you put that kind of code in you make the maintenance (which always require more work than developing) a nightmare. Especially for new people unfamiliar with it. So I would recommend doing it the classic, right way.
-
February 23rd, 2009, 06:56 PM
#15
Re: Calling an API without the Header
its not for any particular application , but for my future application and so i can make it run faster and with smaller code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|