The reason why I have this problem is because I am writing a library for my future software development.
This library provides separate code support for Linux and Windows systems. In the section on file operations, due to some encoding reasons, I need to use many functions to handle the encoding of file path strings.
In the "Open File" operation, you can use the function provided by the WINAPI called CreateFile
or use the FILE pointer
.
So I was thinking, since I am using the Windows system, would it be better to recommend using the functions provided in the WINAPI?
But I think it's a bit troublesome about this, because if that's the case, then I have to modify all my specific code about Windows systems to the functions provided by WINAPI.
Some functions actually have many functions, but they are not as portable as ordinary functions.
For example, opening a file and reading it. Here are some sample codes:
WINAPI
void test()
{
HANDLE *handle = NULL;
uint8_t buff[4096];
memset(buff, 0x00, 4096);
handle = CreateFileA("README.md", GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
ReadFile(handle, buff, 4096, NULL, NULL);
printf("%s\n", buff);
CloseHandle(handle);
}
General code
void test()
{
FILE *fp = fopen("README.md", "rb");
uint8_t buff[4096];
memset(buff, 0x00, 4096);
fread(buff, 1, 4096, fp);
printf("%s\n", buff);
fclose(fp);
}
Since all the functions I want can be implemented, should I use the functions provided by WINAPI?