开发者

Different programming languages possibilities

This should be very simple question. There are many programming languages out there, compiled into machine code or managed code. I first started with ASM back in high school. Assembler is very nice, since you know what exactly CPU does. Next, (as you can see from my other questions here) I decided to learn C and C++. I chose C becouse from what I read it is the language with output most close to assembler-written programs.

But, what I want to know is, can any other Windows programming language out there call win32 API? To be exact, like C has its special header and functions for win32 api interactions, is this assumed to be some important part of programming language? Or are there any languages that have no supp开发者_如何学运维ort for calling win32 API, or just use console to IO and some functions for basic file IO? Becouse, for Windows programming with graphic output, it is essential to have acess to win32 API. I know this question might seem silly, but still please, help me, I ask for study porposes. Thanks.


Lots of different languages have a way of opening and using windows DLL files so you can just open the system DLLs which contain the API functions and use them.

Some languages such as C help you out by providing a nice header file with everything already defined.

The only other language i've ever seen that has direct access to the WinAPI without needing to open any library beforehand is a BASIC dialect called Purebasic.


Are you asking how to call Win32 from assembly?

Just use MASM (or TASM, or...)

Example hello world calling Win32:

==== HelloWin.asm ==============================
.586
.model flat, stdcall

EXTERN MessageBoxA@16:NEAR

.data
szCaption db 'Hello World',0
szAppName db 'HelloWorld',0

.code
start:
push 0
push offset szCaption
push offset szAppName 
push 0
call MessageBoxA@16
ret

end start
===================================================

To assemble:

ml.exe /coff /c HelloWin.asm

To link:

link /subsystem:windows HelloWin.obj /defaultlib:C:\masm32\lib\user32.lib


The first language that I used to get to the Windows API was VB4. Yes most languages can get to the API in some manner.


Win32 functionality is available from C, C++, VB, VB .net and C#. In the later two, you generally use the nice CLR libraries, but you can call native (unmanaged) APIs directly if you know the right syntactic sugar to sprinkle around.

Win32 usage is not limited to the above list. It is a C API for a reason: so that any language that essentially knows how to make the right kind of function call can call them. And in this case, "the right kind" is stdcall. All the language's compiler (or whatever) has to do is load the right DLL, push the arguments (and other info) onto the stack in the right order, and you're good to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜