Prev: Newbie question: Need for header file when linking to static library
Next: using CList as a base class in an extension DLL
From: Uwe Kotyczka on 10 Nov 2009 14:32 Hi, I have been working with VC6.0 for a long time. Now I have access to Visual Studio 2008 (not at home), so I tried to compile an old VC6.0 project with the new IDE. It worked fine and did not require many changes in the code. However there were some warnings that I use depricated functions like fopen, sprintf, _tcsncpy an I better should use their save equivalents fopen_s, sprintf_s, _tcsncpy_s. No problem, the code compiles with those "_s" functions. Reading the MSDN documentation I find that fopen_s is availible from Win95 on. I would like to maintain the project for both VC6.0 and Visual Studio 2008. But in VC6.0 I cannot find any header/lib for fopen_s. Not in the headers which ship with VC6.0SP6 nor in the February 2003 SDK. Am I missing something or is it simply not possible to use functions like fopen_s in VC6.0?
From: Trevor on 10 Nov 2009 17:25 "Uwe Kotyczka" <uwe.kotyczka(a)web.de> wrote in message news:8af895e9-5601-4a6e-92c5-3c8cef0dad5a(a)b2g2000yqi.googlegroups.com... > Hi, > > I have been working with VC6.0 for a long time. > Now I have access to Visual Studio 2008 (not at > home), so I tried to compile an old VC6.0 project > with the new IDE. > > It worked fine and did not require many changes > in the code. However there were some warnings > that I use depricated functions like fopen, > sprintf, _tcsncpy an I better should use their > save equivalents fopen_s, sprintf_s, _tcsncpy_s. > > No problem, the code compiles with those "_s" > functions. Reading the MSDN documentation I find > that fopen_s is availible from Win95 on. > > I would like to maintain the project for both > VC6.0 and Visual Studio 2008. But in VC6.0 I cannot > find any header/lib for fopen_s. Not in the > headers which ship with VC6.0SP6 nor in the > February 2003 SDK. > > Am I missing something or is it simply not > possible to use functions like fopen_s in VC6.0? The easy way is to ignore the warnings and continue doing what you're doing. The hard way is to use #ifdef and check for _MSC_VER to tell the version of the compiler so you can use the safe functions in 2008, but the "unsafe" functions in Visual Studio 6. Some _MSC_VER values are listed here: http://support.microsoft.com/kb/65472. See http://www.gamedev.net/community/forums/topic.asp?topic_id=318410&whichpage=1� for instructions to ignore the deprecated warnings.
From: Kerem Gümrükcü on 10 Nov 2009 17:49 Hi Uwe, > No problem, the code compiles with those "_s" > functions. Reading the MSDN documentation I find > that fopen_s is availible from Win95 on. where did you read that, please show! AFAIK the Security Enhancements are available starting VS2005: [Security Enhancements in the CRT] http://msdn.microsoft.com/de-de/library/8ef0s5kh(VS.80).aspx > I would like to maintain the project for both > VC6.0 and Visual Studio 2008. But in VC6.0 I cannot > find any header/lib for fopen_s. Not in the > headers which ship with VC6.0SP6 nor in the > February 2003 SDK. if there is absolutely no very special need to maintain the project VS6, then i would higly recommend to use the latest VS, since it offers your many many advantages over the old VC6,... >Am I missing something or is it simply not >possible to use functions like fopen_s in VC6.0? Try dynamic loading and via LoadLibrary and GetProcAdress, the do a typedef of the functions signature and just invoke it. I even did something very weird now: I called the fopen_s() and fclose() from within C# and .NET 2.0 runtime, something you would never do due to the powerful System.IO Namespace and/or high-level windows api you can use with PInvoke, but i just tried only to see whether it works or not,..and it works fine! So you can dynamically access the functions just fine! Here is the unusual C# code (on-the-fly translated from headers structures and information, possibly does not work on other systems!): [StructLayoutAttribute(LayoutKind.Sequential)] public struct _iobuf { [MarshalAsAttribute(UnmanagedType.LPStr)] public string _ptr; public int _cnt; [MarshalAsAttribute(UnmanagedType.LPStr)] public string _base; public int _flag; public int _file; public int _charbuf; public int _bufsiz; [MarshalAsAttribute(UnmanagedType.LPStr)] public string _tmpfname; } [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int fopen_s(out _iobuf pFile, [MarshalAsAttribute(UnmanagedType.LPStr)] string filename, [MarshalAsAttribute(UnmanagedType.LPStr)] string mode); [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int fclose(_iobuf stream); _iobuf iob; //FILE structure //open explorer.exe to read int errno = fopen_s(out iob,@"C:\Windows\explorer.exe","r"); // do someting here the _iobuf structure //close explorer.exe fclose(iob); Write your own headers and imports, or even your own classes that will encapsulate aall the dyhamic loading and access of the secure functions of the msvcrt. You should always check the msvcrt version before you try to access the functions! Regards Kerem -- ----------------------- Beste Gr�sse / Best regards / Votre bien devoue Kerem G�mr�kc� Latest Project: http://www.pro-it-education.de/software/deviceremover Latest Open-Source Projects: http://entwicklung.junetz.de -----------------------
From: Giovanni Dicanio on 10 Nov 2009 17:51 "Uwe Kotyczka" <uwe.kotyczka(a)web.de> ha scritto nel messaggio news:8af895e9-5601-4a6e-92c5-3c8cef0dad5a(a)b2g2000yqi.googlegroups.com... > Am I missing something or is it simply not > possible to use functions like fopen_s in VC6.0? These _s functions have been being available since VS2005 (a.k.a. VC8). They are part of the CRT (the so called security enhancements in the CRT), not part of Platform SDK. If you want to get rid of the aforementioned warnings you could #define _CRT_SECURE_NO_WARNINGS (e.g. in "StdAfx.h"): http://msdn.microsoft.com/en-us/library/8ef0s5kh%28VS.80%29.aspx HTH, Giovanni
From: Giovanni Dicanio on 10 Nov 2009 17:52
"Trevor" <trevor(a)nope.com> ha scritto nel messaggio news:uxM$ySlYKHA.528(a)TK2MSFTNGP03.phx.gbl... > Some _MSC_VER values are listed here: > http://support.microsoft.com/kb/65472. There is a list of _MSC_VER values on Joe's rich web site as well: http://www.flounder.com/msdn_documentation_errors_and_omissions.htm#_MSC_VER Giovanni |