views:

95

answers:

4

Hello. 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 support 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.

+2  A: 

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.

Gary Willoughby
Thanks, so windows.h is basically just a "simple" way to win32 api? And for example, does printf() in C use win32 api also? I mean, console is part of win32 api, or isn´t?
B.Gen.Jack.O.Neill
windows.h is just letting your program know what is inside the DLLs in `C:\Windows`. When you import windows.h you can then use the API functions without any more messing about. When using other languages you may have to manually open DLLs files your self to call the functions contained within. printf() is part of the standard library included with all C compilers. The standard library is a smaller library which contains all the basic stuff that needs to be cross-platform. The WinAPI stuff is not cross-platform.
Gary Willoughby
OK, thanks. Can I have one small question more? If standart library is cross-platform, than functions like printf() must be the same in Windows or Linux compilers. So, Windows and Linux must both support it. By support I mean to asign console to process and have the same communication with it. But I thought that only difference between Console app and GUI win32 project is that console app automatically allocates console on start. So I thought that even functions like printf() are platform specific. Becouse, for example Dos used int 21h for output, and I think that Linux used int 80h.
B.Gen.Jack.O.Neill
Yes, a Windows console app does use the WinAPI to allocate a console which opens immediately on launch (if not called from another console). On linux, however, it does not, you have to call the program from a terminal window (once compiled for that platform). Also for input/output stuff don't worry about the hardware, think in streams such as stdin/stdout/stderr for communication. This abstracts away from the hardware details and allows for cross platform programming.
Gary Willoughby
Thanks. But, I as becouse I want to stydy computers more deeply. A think I know how HW works relativelly enough, becouse we had CPU architecture (first 8051 than x86 from 8086 to Pentium 1) in school for 7 hours a week for about 10 months. So now I am just collecting informations about how OS actually use the possibilities of this HW. Mostly I use google, but sometimes I can´t find what I need to know..
B.Gen.Jack.O.Neill
A: 

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.

Dave
A: 

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

GalacticJello
A: 

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.

jeffamaphone