unresolved external symbol _strcpy_s

Hi guru, Can I use strcpy_s in ddk?

when I write code like:
#include <ntstrsafe.h>
void test
{
strcpy_s(0, 0, 0);
}
Sources file: TARGETLIBS=$(DDK_LIB_PATH)\ntstrsafe.lib

I got error:
unresolved external symbol _strcpy_s, for both ddk 3700 and 7600, is there anybody know how to make it work?

Thanks!</ntstrsafe.h>

> Hi guru, Can I use strcpy_s in ddk?

when I write code like:
#include <ntstrsafe.h>
> void test
> {
> strcpy_s(0, 0, 0);
> }
> Sources file: TARGETLIBS=$(DDK_LIB_PATH)\ntstrsafe.lib
>
> I got error:
> unresolved external symbol _strcpy_s, for both ddk 3700 and 7600, is there
> anybody know how to make it work?

It should be fairly obvious: the symbol is not defined in the library,
therefore, the function is not supported.

What are you doing using 8-bit strings in the kernel? Why do you need a
strcpy at all? What is the problem you are trying to solve?
joe
>
> Thanks!
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
></ntstrsafe.h>

> Can I use strcpy_s in ddk?

Roughly speaking in a common case you can not, it worth to prefer using the set of ‘RtlString…()/RtlUnicodeString…()’ functions declared in the ‘Ntstrsafe.h’.

But if you suffering some reasons to use namely ‘C’-string functions there are some options:

(1) the safe subset of ‘C’-string functions (including ‘strcpy_s’) is now exported by ‘ntoskrnl.lib’ starting from the Win-7 and newer. If the driver is intended to be used in Win-7-8-newer there no problems arises, and for the older NTDDI versions you should implement your own ‘C’-string entry point wrappering corresponding function from the ‘Ntstrsafe.h’;

(2) consider to use the unsafe subset of ‘C’-string functions: e.g. ‘strcpy()’ instead of ‘strcpy_s()’. They are exported by ‘ntoskrnl.lib’ at least starting from Win-XP and newer, but using them you shoud carefully do check by your means all the buffers used;

(3) invent something else fulfitting your requirements…

Joe, for test purpose, I just believe strcpy_s can work, but why not in my side, so try to figure out.

kt133a, thanks, yes, you’re right, can work under win7, thanks for your message.

But given its likely usefulness in kernel programming (a value
distinguishable from zero only by using a high-power microscope) why
should you care whether it is defined or not?
Joe

Joe, for test purpose, I just believe strcpy_s can work, but why not in my
side, so try to figure out.

kt133a, thanks, yes, you’re right, can work under win7, thanks for your
message.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

I will take a stronger stance, than Joe. First, there is the problem that
once you write a piece of code, someone will pick it up. I have seen way
too many times a total piece of crap in production code, and tracing it back
this was a test code of some other developer who was respected, and “since
it seemed to do what we wanted to do” got included in the product. Second,
you are teaching yourself bad habits, while we all do things that we think
“I should do better” why in the world would you work at making bad code
function, versus doing it right?

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, January 27, 2014 1:40 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] unresolved external symbol _strcpy_s

Joe, for test purpose, I just believe strcpy_s can work, but why not in my
side, so try to figure out.

kt133a, thanks, yes, you’re right, can work under win7, thanks for your
message.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

xxxxx@gmail.com wrote:

Hi guru, Can I use strcpy_s in ddk?

Yes.

when I write code like:
#include <ntstrsafe.h>
> void test
> {
> strcpy_s(0, 0, 0);
> }
> Sources file: TARGETLIBS=$(DDK_LIB_PATH)\ntstrsafe.lib
>
> I got error:
> unresolved external symbol _strcpy_s, for both ddk 3700 and 7600, is there anybody know how to make it work?

strcpy_s is part of the C run-time library:

#include <string.h>

TARGETLIBS=$(DDK_LIB_PATH)\libcntpr.lib

You might choose to use “RtlStringCchCopy” instead. That is the
<ntstrsafe.h> equivalent of strcpy_s.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.</ntstrsafe.h></string.h></ntstrsafe.h>

Tim, libcntpr.lib can not work, verified here, I think what kt133a has said is right.