compilationoperating-systemmultilingual

Using Functions made in a Language I have not learned


Lets say in theory a programmer is trying to make a program for windows that will simulate mouse or keyboard input. Windows has functions written in C++ that when used together can do just that. If someone programed in C, Rust or another compiled language, that is not C++, what is a good way to make the desired program?

Does the programmer need learn C++ or are there other ways to make the program without learning the language the operating system was programmed in?

Is there a way to do part of the project in the language the programmer is used to and part in the other language? This way the programmer could learn just some of the other language.

I have heard windows is made using C and C++, that is why I thought the last option might be possible.

Side Note: I tried to use the tag "multiple-languages" but it kept being changed to "multilingual".


Solution

  • I think I'm interested in knowing how cross-language calls are done.

    It depends on the languages involved and their respective runtimes:

    In other cases, it can be a lot more complicated:

    When bridging between a managed / garbage collected language (e.g. Python, Java) and a non-managed language (e.g. C, C++), you introduce the risk that something done on the non-managed side will break garbage collector invariants. It is ... complicated.


    So what does this mean in practice?

    1. Your code will be simpler if you stick to one language.
    2. If you need to call a well-known API (or library or function) written in another language, look for an compatibility or "binding" library; e.g. there are libraries for making WinAPI calls in many languages.
    3. If you do end up dealing with the cross-language calls in your own code (i.e. you are implementing the compatibility layer) you probably will need to be fluent in both languages to succeed.

    Often people use cross-language calls because one language is (supposedly) "faster" than the other. But it often doesn't work out; i.e. they don't get the anticipated speedup because of overheads related to the calls. And then there's thread-safety ...