Accesing Win32 API from FlasCC (aka Crossbridge) - c++

I have to compile a C++ project using FlasCC to create a swf. I am able to compile all the CPP files except those that uses Win32 API ("Windows.h", DirectX,etc). I have seen the api libraries on the cygwin folder /usr/include/w32api but not on FlasCC sdk folder. How can I link them?

You can't. Flascc uses FreeBSD API so nothing windows specific can be used at all unless you write it. And even the libc provided is somewhat limited and lot of the API is dummy. Most of the IO and system dependent code needs to be rewritten to be used with flascc.

Related

'windows.h', what about other platforms?

I'm using visual studio on windows and I have this header file called windows.h which of course gives me access to the win32 API.
but when I try to use other platforms API like the linux API for example. I don't find any header file with that name, which mean that I can't use any other OS API than windows,
now the problem here is: what if I wan't to make a cross platform program for example ? when I don't have the appropriate access to its API, I tried to do some researches for a sometime but couldn't get any answer to my questions, which is really troubling my mind right now, so to be more specific these are my questions:
1- why I can only use the windows API out of all the other operating systems ?
is it because I'm coding on windows, so if I was coding "somewhere else" it would be different ?
or is it something related to the compiler itself ?
2- what if I want to use another API do I have to use an external library ? and if that's the case how is the Standard Library in c++ cross platform, I mean if it is cross platform then there should exist other platform specific headers provided by the library right ?
I'm using visual studio on windows and I have this header file called windows.h which of course gives me access to the win32 API.
Strictly speaking windows.h is sort of a meta-header. Some important macros, tokens and symbols are defined in windows.h, but it also pulls in a lot of other headers. If you look at the reference manual of each of the Win32 API functions it will tell you there, which header that function is declared in. Let's have a look at CreateFileA for example: At the bottom of the reference manual you'll find:
Requirements
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps onliy]
Target Platform Windows
Header fileapi.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll
So this tells us, that CreateFileA actually is declared in fileapi.h and is exported from the kernel32.dll system library.
but when I try to use other platforms API like the linux API for
example.
That is, because there is no linux.h API header (if you search a Linux development system for files named linux.h you'll find plenty, but those are not used for the system level API).
The reason for that is, that Linux doesn't have its very own, proprietary API, but folloes the POSIX industry standard for operating system APIs, and the Single Unix Specification maintained by the Open Group.
There are of course Linux specific APIs, but you can safely ignore them for "usual" application development; you need those if you're doing low level stuff, like writing a C runtime library, or custom memory allocators.
Of most interest for you, as a developer are the manpages in section 2 (calls into the operating system kernel = syscalls) and section 3 (library functions). https://linux.die.net/man/
The POSIX equivalent to CreateFileA would be open which you can find in section 2: https://linux.die.net/man/2/open (or the creat syscall, that exists for legacy reasons, but nobody uses that (or should use it)).
If you look at the manpage of open it tells you
open(2) - Linux man page
Name
open, creat - open and possibly create a file or device
Synopsis
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);
That tells you, that in order to use open you need to include sys/types.h, sys/stat.h and fcntl.h. Unlike Windows there's no all overencompassing header that pulls in everything. The reason for this is, that for backwards and cross compatibility reasons the things that are exposed by a header can be configured by setting certain macros to specific values before including the header. Those are explained in feature_test_macros(7), and for functions where they apply these are also mentioned in the respective manual page.
I don't find any header file with that name, which mean that
I can't use any other OS API than windows,
Just because you can't find it, doesn't mean it doesn't exist.
now the problem here is: what if I wan't to make a cross platform program for example?
Then you write all the platform specific things into a separate .c file, that encapsulates the OS stuff.
when I don't have the appropriate access to its API
Well, you do.
1- why I can only use the windows API out of all the other operating systems?
Because you can't. Windows.h is available only on Windows systems.
2- what if I want to use another API do I have to use an external library?
Then you just use it.
Keep in mind that in Linux the graphical environment is not part of the main operating system. It's in fact a regular program that is automatically launched on system start. Hence you won't find documentation for that in the aforementioned manpages.
The default graphics enviroment for Linux is Xorg (an open implementation of the X11 display system). There's also Wayland, but after over 10 years in development it's still poorly supported and leaves a lot to be desired.
If you want to program X11 on the same level as Win32, you'll have to deal with the Xlib or Xcb. However direct X11 programming is quite tedious. You probably want to use some nice application framework like Qt or GTK. Qt by itself is a cross platform framework, so if you limit yourself to use only, and only Qt functions, your program will be fully cross platform without extra effort. If you want to do 3D graphics on the GPU, use the cross platform APIs OpenGL or Vulkan.
but when I try to use other platforms API like the linux API for example. I don't find any header file with that name
There is no header called <linux> for the system API. The POSIX operating system specification (which Linux conforms to) lists several headers which contain the functionality that you might find from windows.h on that system. POSIX spec overlaps with the C standard library, and the C standard library implementation also provides the POSIX specific headers. See the Linux manual or POSIX spec for full list of headers.
what if I want to use another [system] API
You will need at least the header files of that API in order to compile programs that call them. Furthermore, you'll need the library archives in order to link your programs. And you'll need to tell the compiler which system you are targeting. By default, all compilers assume that you target the system that is running the compiler. You'll need to consult the documentation of your compiler about whether cross compilation is possible, and how to do it.
Or a simpler approach: Compile on the system where the API is provided. The headers may need to be installed separately.
... how is the Standard Library in c++ cross platform
Each system has their own standard library. Some of the implementations of standard library are cross platform, but not all. For example, the libstdc++ - which is the standard library that is part of the GNU project, and is the default standard library in Linux - is available on many platforms including Windows. By contrast, the Msvc standard library is only available on Windows.
The Wikipedia about windows.h library says:
windows.h is a Windows-specific header file for the C and C++
programming languages which contains declarations for all of the
functions in the Windows API, all the common macros used by Windows
programmers, and all the data types used by the various functions and
subsystems.
Linux doesn’t provide a default API for window management as does Windows so if you are programming a graphical application then you need to choose a windowing library as well.
The answer to part one is yes. You can only use the Windows API because you are programming on Windows. However you can run Linux on Windows. A Microsoft product called the Windows Subsystem for Linux allows you to do that. But even if you do that you won't find a header called linux.h, it's more complicated than that. There is also a product (called WINE I believe) that lets you use the Windows API on Linux, although I believe it has a few issues.
The standard library interface is cross platform, but it's implementation certainly isn't. It does this by abstracting away OS specific features. If you look at how the library is implemented on different platforms you will certainly see lots of differences.

Needed info for libcurl, cross-platform

I want to implement an auto-update or update notification method for my open-source project. My searches often lead me to libcurl.
I search much about HTTP-libs - and many times I ended up with libcurl ... but can I use it for Linux and Windows together?
My wish is to include only header-files (same header for Linux & WIndows, if possible) and add only OS-spefic lib flags with cmake or visual-studio project files. That way, I can compile the same code on both platforms.
Is that possible in general with libcurl? If yes, how do I do that directly?
Yes you can.
An application can use libcurl on both Linux and Windows with the source code parts that do the HTTP transfers being identical. libcurl provides the same API and it works the same on a vast amount of different operating systems.

How to Use OpenSSL project in my Windows C++ application?

I have query related to how to use OpenSSL project in my C++ application.
I saw there was one installer that was registering the library and then we have to use this library in our application.
But actually I have my own project where I want to use openssl .c and .h files without using dll.
How can i do this?
Normally using DLLs is a good idea because it will enable others (that don't have your sourcecode) to update the openssl version in use by your program.
When we consider the plethora of security issues from the last months this is a good thing ...
If you still want to statically include the openssl code into your program you can do so by including the files into your project and calling them directly.
See stackoverflow for examples, this might be one that fits your scenario: How do I build OpenSSL statically linked against Windows runtime?

Program which Compile by Code::Block plus MinGW, but Using Standard Windows Library?

everyone.
I am a newer for c++, and I had some experience on c#. I want to create a pure c++ developing environment, and using the standard c++ library. My operation system is Windows.
I choose code::block+MinGW to build a pure developing environment on Windows. I directly choose Code::Block installation packet which integrate MinGW. Then I began to develop my first learning project. And In this project, I used the function "stat" to get file information from standard library. And I passed the compile. But during operation this program, I checked the "Call Stack". And found the function "stat" called from file "C:\WINDOWS\system32\msvcrt.dll". And I checked this dll from internet, and found this file is a microsoft windows library file. So it obviously, this dll file don't have the function "stat", but have the function "_stat".
So how do I solve this problem? I want to use the standard c++ library, not the microsoft windows library. Because later, I want to move this project to linux environment. So overall, how do I build the developing environment to satisfy my requirement.
You have to use the windows system libraries if you're building for Windows. You simply link one or the other depending on the target system. The libraries merely provide the underlying implementation, which is different from one OS to the next.
In your specific example, stat is a function defined by standard system headers, but its underlying implementation will vary from system to system. It's possible that the entire function is pulled from msvcrt, but my guess is that msvcrt happens to implement a companion function which deals with all the system-specific stuff.

Using Component Object Model (COM) on non-Microsoft platforms

I'm regularly running into similar situations :
I have a bunch of COM .DLLs (no IDL files) which I need to use and invoke to be able to access some foreign (non-open, non-documented) data format.
Microsoft's Visual Studio platform has very nice capabilities to import such COM DLLs and use them in my project (Visual C++'s #import directive, or picking and adding them using Visual Basic .NET's dialogs) - and that's the vendors recommended way to use them.
I would be interested into finding a way to use those DLLs on non-microsoft development platforms. Namely, using these COM classes in C++ project compiled with MinGW or Cygwin, or even Wine's GCC port to linux (compiles C++ targeting Win32 into binary running natively on Linux).
I have got some limited success using this driver, but this isn't successful in 100% of situations (I can't use COM objects returned by some methods).
Has someone had success in similar situations ?
Answering myself but I managed to find the perfect library for OLE/COM calling in non-Microsoft compilers : disphelper.
(it's available from sourceforge.net under a permissive BSD license).
It works both in C and C++ (and thus any other language with C bindings as well). It uses a printf/scanf-like format string syntax.
(You pass whatever you want as long as you specify it in the format string, unlike XYDispDriver which requires the arguments to exactly match whatever is specified in the type library).
I modified it a little bit to get it also compile under Linux with WineGCC (to produce native Linux elf out of Win32 code), and to handle "by ref" calls automatically (stock disthelper requires the programmer to setup his/her own VARIANT).
My patched version and patches are available as a fork on github:
https://github.com/DrYak/disphelper
And here are my patches :
patch for single source
patch for split source
The problem with the Ole/Com Object Viewer packaged with Visual Studio and Windows SDKs is that it produces a broken .IDL out of the .DLL, which can't further be compiled by MIDL into a .H/.CPP pair.
Wine's own reimplementation of OleViewer is currently unstable and crashes when trying to use those libraries.
I think you should be able to use the free tool Ole/Com Object Viewer to make the header files.