|
-
Sep 6th, 2004, 07:49 PM
#1
Thread Starter
Fanatic Member
what is the API and what is the Founction of API
hello
what is the API and what is the Founction of API
and can you give example with it
and thankyou for help
-
Sep 6th, 2004, 08:32 PM
#2
API stands for Application Programming Interface. And what API does is allow programming languages to access any external DLL's (Dynamic Link Library) subs/functions that are in it. Kinda like external modules. What's great about DLL's is that they can be created on any programming language (with DLL compile support of course) and be used on other programming languages as well as it's own. A basic API declaration for example would be this:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
-------------------------------------------------------------------------------
CopyMemory - copies a block of memory from one location to another.
Parameters:
Destination - Pointer to the starting address of the copied block's destination.
Source - Pointer to the starting address of the block of memory to copy.
Length - Size of the block of memory to copy, in bytes.
-------------------------------------------------------------------------------
Let's break it down shall we.
1.) First of all, the part after Private Declare Sub where it says CopyMemory, this is the name of the sub (or function if it's Private Declare Function) you are going to use. And whats great about this part is it can be called anything, as long as the Alias "ActualNameFromDLLHere" is there which I'll get to in a minute. It can be called Copy_Memory or memcopy (c++ name for it) or Blahblah or whatever. Traditionally for VB programmers though, they call it CopyMemory.
2.) Lib means "Library" or what I like to call "What DLL library shall we use." Right here, you can include the path where the DLL is located "C:\YourDLL.dll" or exclude the path which automatically looks in the C:\Windows\System\" directory (or System32 if you have Windows XP or any other operating system that has that.) When you have the DLL name there, you can have either the fullname with the extention "kernel32.dll" or leave the extention out "kernel32".
3.) Alias "RtlMoveMemory". This deserves to be looked into. What this has is the ACTUAL name of the sub/function routine that is located in the DLL which is RtlMoveMemory. Now if you were to call the API RtlMoveMemory you can have it declared this way:
Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal Length As Long)
Notice that the Alias is gone. What's great about having the Alias is that you don't need to call your sub RtlMoveMemory since in your opinion might be confusing to you using it while you program.
You can give it any name you want, as long as the Alias is there.
4. Now this is where the arguements of the API can be placed. And it has to match with how it is in the DLL by the data type (Long, Integer, Single, etc.) and how many arguements. Like for example, Test(Length As Long,Result as Long) in Visual Basic matches with Test (int Length, int Result) in C++ with both having two arguements. What Any means that it is a pointer data type. Pointers are another story, but you can use this type as a variant as well, hence the word Any.
Now you can use it like any other sub or function. And what's great is that you can do so much more than what Visual Basic is capable of, and faster. I hope you weren't confused by this in any way and also hope I answered your question. Happy coding!!!
Easy Begginner API Code Example:
'----------------------------------------------------------------------
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Activate()
Dim Num_A As Long
Dim Num_B As Long
Num_A = 10
CopyMemory Num_B, Num_A, 4 'Long is a 4 byte data type.
Print Num_B
End Sub
'----------------------------------------------------------------------
Output is 10
Last edited by Jacob Roman; Sep 6th, 2004 at 10:51 PM.
-
Sep 6th, 2004, 10:25 PM
#3
Actually API stands for "Application Programming Interface".
Check out this site for tutorials, sample code, and references.
allapi.net
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 6th, 2004, 10:50 PM
#4
Yeah you might be right. I did a Google search on what API stands for while writing this. I'll change it.
-
Sep 6th, 2004, 11:16 PM
#5
Instead of google, search microsoft. Faster and you know if they
say its Application then your sure its Application.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 6th, 2004, 11:29 PM
#6
-
Sep 6th, 2004, 11:34 PM
#7
Thread Starter
Fanatic Member
oky thankyou for help
and I think the api it means programming on the windows and we can
use this cod ein the c++ or c is that truth ?
and can you explanation the code pleas
-
Sep 6th, 2004, 11:45 PM
#8
'Your API declaration
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'This code will run automatically when first
'running the program.
Private Sub Form_Activate()
'These variables will hold a number.
'Variables are known to be storages in memory,
'which is why copymemory copies one block of
'memory to another.
Dim Num_A As Long
Dim Num_B As Long
'Can we get any more obvious?!!!
Num_A = 10
'Copy's Variable Num_A (Source) to Num_B (Destination)
'Equilivant to Num_B = Num_A only theoretically faster.
CopyMemory Num_B, Num_A, 4 'Long is a 4 byte data type.
'Here is a list of some data types and their bytes, which is important using it with CopyMemory:
'-----------------------------------------------
'Byte 1 Byte
'Integer 2 Bytes
'Long 4 Bytes
'Single 4 Bytes
'Double 8 Bytes
'Variant 16 Bytes (if numeric)
'String 10 Bytes + String Length (unless fixed length)
'-----------------------------------------------
'If you copy a Long variable to and Integer variable, for example,
'you will get ugly results.
'Prints the output on the screen which is 10.
Print Num_B
End Sub
Last edited by Jacob Roman; Sep 6th, 2004 at 11:52 PM.
-
Sep 6th, 2004, 11:47 PM
#9
Oh and don't call API "the api" cause "the api" means you are refering to a specific api, not API itself. Watch your spelling and grammar too cause I'm having a little trouble following you. Take your time typing it out, don't rush it, even if you are from syria. Do your best on typing in English.
Last edited by Jacob Roman; Sep 7th, 2004 at 12:37 AM.
-
Sep 6th, 2004, 11:48 PM
#10
CopyMemory can also come in handy in copying massive arrays into another, which is what I love about it. I do that in my 3D engines.
-
Sep 7th, 2004, 12:01 AM
#11
And API's are compatible with ALL programming languages. Unless it's a crappy programming language that doesn't support the use of external DLL's. Plus the declaration of an API would obviously be different than Visual Basic's when doing API on another language. With C++, all you have to do is use an #include statement. Majority of the API used in VB are also located in the header files that come with C++ that already have the code that makes calls to subs and functions from external DLL's.
#include <stdio.h> //needed for printing
#include <memory.h> //this has memcopy (CopyMemory) as well as so much more.
int main(void)
{
int num_a;
int num_b;
num_a = 10;
memcopy (num_b,num_a, sizeof(int)) ;
printf("%d\n",num_b);
return 0;
}
Last edited by Jacob Roman; Sep 7th, 2004 at 12:35 AM.
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
|