Discussion:
How to change _wfopen_s for BCB?
(too old to reply)
James5950
2008-03-07 15:23:10 UTC
Permalink
Dear All,

How to change _wfopen_s for BCB? or any instead?

Thank for any comments,
Best regards,
James
Darko Miletic
2008-03-07 16:49:53 UTC
Permalink
Post by James5950
Dear All,
How to change _wfopen_s for BCB? or any instead?
In BCB there is _wfopen. Add stdio.h to use it.

FILE *fileHandle = _wfopen(filename, filemode);

You must understand that all these _s functions microsoft invented are
there just for better safety (so they say). All of them have name formed
like this : <existing_function>_s . It is safe for the test purporses to
replace _s functions with ones without _s with some minor changes in
paramteres. There is no need to ask every time you need to replace a
function. Just go to the MSDN and see the documentation for both version
of functions (_wfopen_s and _wfopen in this case) to know what needs to
be changed.

In BCB _wfopen_s could be quickly implemented like this :

#include <errno.h>
#include <stdio.h>

int __cdecl _wfopen_s( FILE **pFile,
const wchar_t *filename,
const wchar_t *mode ) {

*pFile = _wfopen(filename, mode);
return errno;
}
Alex Bakaev [TeamB]
2008-03-07 17:11:42 UTC
Permalink
Post by Darko Miletic
You must understand that all these _s functions microsoft invented are
I think it should be possible to use the MSFT functions by linking
dynamically to their RTL. The functions have C linkage and are not
mangled, so it should be possible to use them by creating an import
library for one of the msvcrt*.dll
Darko Miletic
2008-03-07 17:25:23 UTC
Permalink
Post by Alex Bakaev [TeamB]
I think it should be possible to use the MSFT functions by linking
dynamically to their RTL. The functions have C linkage and are not
mangled, so it should be possible to use them by creating an import
library for one of the msvcrt*.dll
Ms CRT library is not that transaparent for general use. It would take a
bit more work to make use of it in BCB.

A starting point would be here
http://www.hailstorm.net/papers/smallwin32.htm
http://www.microsoft.com/msj/archive/S569.aspx

But it still does not justifies all that work for only few functions
that can easily be replaced.
Alex Bakaev [TeamB]
2008-03-07 19:11:00 UTC
Permalink
Post by Darko Miletic
Ms CRT library is not that transaparent for general use. It would take a
bit more work to make use of it in BCB.
I think the links you gave do more than what's needed...

James5950
2008-03-07 17:28:28 UTC
Permalink
Thanks Darko,
Post by Darko Miletic
You must understand that all these _s functions microsoft invented are
there just for better safety (so they say).
I am clear.
MS change order of parameter, let me confuse...

Best regards,
James
Loading...