Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change _wfopen_s for BCB?

16 views
Skip to first unread message

James5950

unread,
Mar 7, 2008, 10:23:10 AM3/7/08
to
Dear All,

How to change _wfopen_s for BCB? or any instead?

Thank for any comments,
Best regards,
James

Darko Miletic

unread,
Mar 7, 2008, 11:49:53 AM3/7/08
to
James5950 wrote:
> 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]

unread,
Mar 7, 2008, 12:11:42 PM3/7/08
to
Darko Miletic wrote:

> 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

James5950

unread,
Mar 7, 2008, 12:28:28 PM3/7/08
to
Thanks Darko,

> 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

Darko Miletic

unread,
Mar 7, 2008, 12:25:23 PM3/7/08
to
Alex Bakaev [TeamB] wrote:
>
> 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]

unread,
Mar 7, 2008, 2:11:00 PM3/7/08
to
Darko Miletic wrote:

>
> 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...

0 new messages