MSVCRT.dll, secure functions and winxp

I have a NetShell helper DLL that uses a few secure functions such as
wcsrtombs_s. It currently statically links against the C runtime but
I’ve been wondering if it’s possible to link dynamically instead. The
problem is that the Windows XP version of MSVCRT doesn’t have the
secure functions, so the DLL fails to load. I found
http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/
which explains a solution using msvcrt_winxp.obj, but since I can’t
find any documentation on MSDN I’m wondering if it’s a supported
solution, or if should continue statically linking for the few functions
I need?


Bruce Cran

>I have a NetShell helper DLL that uses a few secure functions such as

wcsrtombs_s.

In Windows, I would suggest to use StringCchXxx and StringCbXxx instead.

Also I would suggest to forget multi-byte strings in Windows, forever, only use the Unicode strings.

problem is that the Windows XP version of MSVCRT doesn’t have the
secure functions, so the DLL fails to load

The abovementioned StringXxx are free from this limitation.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

If you search MSDN for redist you will find how to install the
redistributables files. You need to run vcredist_x86.exe on the target
system.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of Bruce Cran
Sent: Wednesday, December 30, 2009 6:50 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] MSVCRT.dll, secure functions and winxp

I have a NetShell helper DLL that uses a few secure functions such as
wcsrtombs_s. It currently statically links against the C runtime but I’ve
been wondering if it’s possible to link dynamically instead. The problem is
that the Windows XP version of MSVCRT doesn’t have the secure functions, so
the DLL fails to load. I found
http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-usi
ng-visual-c-2005/
which explains a solution using msvcrt_winxp.obj, but since I can’t find any
documentation on MSDN I’m wondering if it’s a supported solution, or if
should continue statically linking for the few functions I need?


Bruce Cran


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

On Wed, 30 Dec 2009 08:08:02 -0500
“Bill Wandel” wrote:

> If you search MSDN for redist you will find how to install the
> redistributables files. You need to run vcredist_x86.exe on the target
> system.

The problem is that by adding USE_MSVCRT=1 to the sources file the
NetShell DLL is linked against MSVCRT.dll, not MSVCRTxx.dll - so I don’t
think installing the Visual C++ Runtime will help. I’ll probably end
up rewriting the kernel code to use unicode throughout, since it’ll
both avoid this issue and end up with simpler code.


Bruce Cran

>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Bruce Cran
> Sent: Wednesday, December 30, 2009 6:50 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] MSVCRT.dll, secure functions and winxp
>
> I have a NetShell helper DLL that uses a few secure functions such as
> wcsrtombs_s. It currently statically links against the C runtime but
> I’ve been wondering if it’s possible to link dynamically instead. The
> problem is that the Windows XP version of MSVCRT doesn’t have the
> secure functions, so the DLL fails to load. I found
> http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-usi
> ng-visual-c-2005/
> which explains a solution using msvcrt_winxp.obj, but since I can’t
> find any documentation on MSDN I’m wondering if it’s a supported
> solution, or if should continue statically linking for the few
> functions I need?
>
> –
> Bruce Cran
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

The answer is do not use the use_msvcrt=1. The xp version of msvcrt does not export the crt *_s routines

d

-----Original Message-----
From: Bruce Cran
Sent: Wednesday, December 30, 2009 5:52 AM
To: Windows System Software Devs Interest List
Cc: xxxxx@bwandel.com
Subject: Re: [ntdev] MSVCRT.dll, secure functions and winxp

On Wed, 30 Dec 2009 08:08:02 -0500
“Bill Wandel” wrote:

> If you search MSDN for redist you will find how to install the
> redistributables files. You need to run vcredist_x86.exe on the target
> system.

The problem is that by adding USE_MSVCRT=1 to the sources file the
NetShell DLL is linked against MSVCRT.dll, not MSVCRTxx.dll - so I don’t
think installing the Visual C++ Runtime will help. I’ll probably end
up rewriting the kernel code to use unicode throughout, since it’ll
both avoid this issue and end up with simpler code.


Bruce Cran

>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Bruce Cran
> Sent: Wednesday, December 30, 2009 6:50 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] MSVCRT.dll, secure functions and winxp
>
> I have a NetShell helper DLL that uses a few secure functions such as
> wcsrtombs_s. It currently statically links against the C runtime but
> I’ve been wondering if it’s possible to link dynamically instead. The
> problem is that the Windows XP version of MSVCRT doesn’t have the
> secure functions, so the DLL fails to load. I found
> http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-usi
> ng-visual-c-2005/
> which explains a solution using msvcrt_winxp.obj, but since I can’t
> find any documentation on MSDN I’m wondering if it’s a supported
> solution, or if should continue statically linking for the few
> functions I need?
>
> –
> Bruce Cran
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>The answer is do not use the use_msvcrt=1. The xp version of msvcrt does not export the crt *_s

routines

Nevertheless, StringCchXxx do work OK being built (for user mode) by w2k build env of .18002 with use_msvcrt=1.

I think they use things like snprintf() internally, and not _s versions.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

_vsnprintf is what (rtl)strsafe.h uses, either in its on static lib for win2k or via an import on xp and later. No need to guess though, the entire impl of each function is in the header

d

-----Original Message-----
From: Maxim S. Shatskih
Sent: Thursday, December 31, 2009 3:00 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] MSVCRT.dll, secure functions and winxp

>The answer is do not use the use_msvcrt=1. The xp version of msvcrt does not export the crt *_s
>routines

Nevertheless, StringCchXxx do work OK being built (for user mode) by w2k build env of .18002 with use_msvcrt=1.

I think they use things like snprintf() internally, and not _s versions.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer