Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Hello programmers !

I know is a crazy question, frenzy and very klutzy, but is there any one asks herself how he can program an application without using Win32 API?

I have this question since a very large time and I don't have any answers until the moment. To know how to program without other tools made you a strong programmer and made you very creative. I know how is very difficult to do such kind of programming, but I want to find out a complete reply on this subject and I think that people here who like discovering new things have the possibility to do that. So, anyone have an idea or ideas on how to reach such dream :)?

Ok, this is a part of my view, the other part is to program a complete executable without relying on windows libraries. Let me explain my proper view, you know and all people know that when we compile a source code using a compiler, supposing a little C program, the compiler converts the source code from the C language which is a high level programming language to Assembly language which is a low level programming language. Afterwards, the Assembly Code automatically will be translated using an Assembler to the binary code; which is the main language of the computer precisely the processor. So, let us understand what all the steps do until now, in this point we have the binary code in its entirety and this code will be an executable using a Linker. Let me ask a question, is the functions included in windows libraries have translated to the binary code?

Of course, the answer is "yes". So, why we cannot write our own functions and our own applications without using these libraries if the code will be translated finally to the Binary Code ?
How programmers in the first ages make their programs when these libraries are not coded yet ? Or let me ask the prominent question, how they program these libraries that give us the possibility to code our own programs using them?

I don't want to reinvent the wheel, but my aim is to know these tricks :). In order to not misunderstand the aim of my question, what I want to do is to program without any linking libraries such as(kernel32.dll, ntdll.dll, etc.).

I mean programming in pure language like 0s and 1s. Hope you understand what I meant :)
Posted
Comments
[no name] 18-Oct-14 17:32pm    
If you do not use the already existing libraries then you are reinventing the wheel. Assembly language is probably the closest that you will be able to get.
Sergey Alexandrovich Kryukov 18-Oct-14 22:14pm    
You are not getting it.

What's wrong with "reinventing the wheel"? The question is about principal possibility of such thing, and this question is interesting enough, hard to answer. It is important for understanding of the very fundamental principles of OS.

I tried to answer, please see.

—SA
[no name] 19-Oct-14 7:23am    
You are not getting it yourself. He explicitly said that he did not want to reinvent the wheel.
BlOcker Mslm 19-Oct-14 7:25am    
But "not reinvent the wheel" doesn't mean that I don't want to do that :)
[no name] 19-Oct-14 9:20am    
Then why did you say it? You explicitly said that you did not want to reinvent the wheel all the while asking how to reinvent the wheel.

Your considerations look very true-like, but you are doing some implicit assumptions which break the logic. Basically, the considerations about 0s and 1s are irrelevant. Everything on a computer is made of 0s and 1s; and OS calls are also made of those 0s and 1s. The question remain open: do you always need to do this call.

First of all, it is apparent: not always. You can create some limited class of "programs" (let's be more formal: executable files, PE files) which won't use any OS calls at all. And it even makes sense. What are the limitations? You won't be able to use any IO, in the sense of using system peripherals, won't be able to allocate any memory (you cannot program without it, because you would then use the memory block allocated by the executable loader, part of OS), won't be able to create thread, use thread synchronization and communication with other processes (IPC). Without all that, you still can implement some useful algorithm (still, in a limited class, because even some formal and abstract algorithms need memory allocation, the use of heap). You can export any static functions doing any calculations; in EXE file, you can use its entry point ("main" function) to output result of any calculations represented as one integer value. Other programs can use your module created under these limitations.

But you may still question: why not using I/O and all I described above as a set of limitations, in a fully stand-along application? In my interpretation, this is reduced to the question: where is your subtle logical mistake which led to not understanding why this is impossible? This is harder to explain.

The subtle mistake is: 1) you did not take into account that OS is not a set of executable file; the difference is: during OS bootstrap, part of OS becomes permanently loaded; 2) you did not take into account hardware protection.

Note that most modern versions of Windows systems use Intel CPUs which has protected mode. In protected mode, you can create some code or data segments which are permanently closed for direct access from some other code segments. The protection cannot be bypasses, because it is implemented in hardware. Some part of software is loaded in so-called kernel mode which confines access to many important resources inside certain protection ring. All application processes can get access to such resource only indirectly, by delegating a request to the inner protection ring.

How is looks in practice? For example, in documentation, you can read absolute range of physical addresses of a video card and set of ports used for output to the screen. So, you can write to screen by setting certain screen modes using the port output CPU instructions, and write to physical address of the card to output characters and pixels. Well, try to do it. All you can get is access violation (in OS terms, it will be General Protection Fault). And, mind you, it will be a hardware exception generated directly by the CPU. Such operations are reserved to the kernel only.

This is why would you need some OS calls. They actually delegate the access to the video card ports and memory to the kernel-mode part of OS. The CPU has the special mechanism for interaction between different rings. The physical access is done in kernel mode.

The system is much more complicated than I tries to describe. There are drivers; some of them are kernel-mode, and the drivers can be loaded dynamically, in a plug-and-play manner, without a need to reboot the OS. Yet, nothing on this level works without OS API. Also, all of the above is related to Windows and some other systems with similar approach, which also includes Linux. Some OS may not employ such protection.

To understand further detail, you would need to study CPU architectures and protected mode. To start with, please see:
http://en.wikipedia.org/wiki/Protection_ring[^],
http://en.wikipedia.org/wiki/Protected_mode[^],
http://en.wikipedia.org/wiki/Hybrid_kernel[^] (the type of kernel of the modern Windows OS,
http://en.wikipedia.org/wiki/Windows_NT[^].

—SA
 
Share this answer
 
Comments
George Jonsson 19-Oct-14 4:41am    
Really good effort to explain.
+5
Sergey Alexandrovich Kryukov 19-Oct-14 12:24pm    
Thank you, George.
—SA
CPallini 19-Oct-14 9:22am    
[On behalf of the OP]
Sergey Alexandrovich Kryukov
Thank you for your great explanation Smile | :)
That's great!
But, how to program in Binary Code for x86 Processor ?
BlOcker Mslm 19-Oct-14 9:46am    
Why the question has closed ?
I don't understand anything !
CPallini 19-Oct-14 10:26am    
Really I don't know. I just moved your comment here (it is not a solution).
Waiting for other solutions...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900