How do i run my app on any OS when the app includes Windows Api ?
I am creating an app and i am creating it with windows api ( app includes windows api code ) now when i deploy my app how could i let my app run in any OS ? which means the windows api code should get converted to Mac api if ran in Mac same with other os ? **
You will need to make the same code AGAIN for Mac.
Then inside the program use defines to control what part of the code should be compiled.
So when you compile your code on Mac with Xcode it will take that code instead.
so slowly your code will become
#ifdef _WIN32 //define something for Windows (32-bit and 64-bit, this part is common) #ifdef _WIN64 //define something for Windows (64-bit only) #endif #elif __APPLE__ #include "TargetConditionals.h" #if TARGET_IPHONE_SIMULATOR // iOS Simulator #elif TARGET_OS_IPHONE // iOS device #elif TARGET_OS_MAC // Other kinds of Mac OS #else # error "Unknown Apple platform" #endif #elif __linux__ // linux #elif __unix__ // all unices not caught above // Unix #elif defined(_POSIX_VERSION) // POSIX #else # error "Unknown compiler" #endif
So then you wish all code could just be the same and hence Qt was born. :)
So native programming is time consuming if you also want to be cross platform.
@mrjj do i have to write code for Mac api from scratch ? isn't there any way to just write code for any api and then it gets converted to a particular Os's api automatically ?
yes, that's what QPA (qt platform abstraction) does. If you use an OS API directly, however, how can you expect it to magically work?
@VRonin simple, just inspect the statement and figure out which Os does the statement belong to and convert the statement to other relevant Os's statements.
- isn't there any way to just write code for any api and then it gets converted to a particular Os's api automatically ?
That would be nearly impossible to create such tool.
Windows contains thousands API calls and Mac might not have evenly remotely
the same concepts in its API. And reverse. Mac has features not seen in windows. etc.
So hence we use a framework as Qt as not to have to write the same code for each platform we want to support.
Maybe You can tell why you want to use native api calls?
What does it do for you that you cannot use Qt for?
Simple? You never developed for several platforms, right? Differences between different platforms and their APIs are huge. Even platforms providing same APIs are not exactly same. For example UNIX with posix: if your application works fine on Linux that does not mean it will work just fine on FreeBSD even if it only uses posix.
If it would be simple we would have such converter.