steveha
steveha

Reputation: 76715

Most basic way to open a file in Windows

I am writing a library that will be statically linked (to other libraries or to applications). I want to make my library as small as possible. My library needs to read a file; the name of the file will be known in advance and contains only ASCII characters. My library will have absolutely no user interface or GUI code; it's just functions to be called.

What function should I call to open my file, with the linker bringing in as little additional code as possible?

Presumably CreateFile() is a basic built-in Windows feature that lives in a shared library. So, should I just use CreateFileA() (to avoid a conversion to wide char)?

For CreateFileA() I will need to include Windows.h; will this increase the size of my library? If so, does defining WINDOWS_LEAN_AND_MEAN help?

Should I just use _open()? Or, I guess it should be _sopen_s() now?

Upvotes: 3

Views: 216

Answers (1)

Joel Lucsy
Joel Lucsy

Reputation: 8706

_open and it's derivatives use the standard c library, which will typical add size to your library. CreateFile is the way to go. A or W depends if you need to link in Unicode, which will depend on what you're linking with.

Upvotes: 2

Related Questions