1
#include <ntddk.h>
#include <string.h>

.....

PWCHAR tmpBuf = NULL, pwBuf = NULL;;

tmpBuf = ExallocatePoolWithTag(NonPagePool, (MAX_SIZE + 1) * sizeof(WCHAR), BUFFER_TAG);
pwBuf = ExAllocatePoolWithTag(NonPagedPool, (MAX_SIZE + 1) * sizeof(WCHAR), BUFFER_TAG);

RtlStringCchPrintfW(tmpBuf, MAX_SIZE + 1, L"ws", ProcName);

pwBuf = wcstok(tmpBuf, L"\\");

...

Error message:

error LNK2019: unresolved external symbol _wcstok referenced in function

But. wcslen works

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
koala
  • 21
  • 4
  • What versions of compiler/ddk/etc? See if [Breaking Changes in Visual C++ 2015](https://msdn.microsoft.com/en-us/library/bb531344.aspx#BK_CRT) maybe applies - look for the `wcstok` section. – dxiv Jan 18 '16 at 05:33
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Jan 18 '16 at 06:08
  • The libraries available in kernel are not the same as usermode. wcstok may not be tbere – mksteve Jan 18 '16 at 06:52
  • Visual Studio 2013, WDK 8.1 – koala Jan 18 '16 at 06:53
  • Are you compiling in C or C++ mode? – chqrlie Jan 18 '16 at 09:39

1 Answers1

0

Microsoft might be trying to force you to use wsctok_s instead of standard conforming but non-reentrant wsctok, especially in device driver code linked with the Windows kernel.

If strtok_s is missing too, it means the C library for kernel and driver development is incomplete. You are in a hosted environment, parts of the Standard C library may be missing.

Note that you are not using an old prototype for wcstok(): Microsoft changed the prototype for wcstok in its VisualStudio 2015 to bring it in conformance with the C Standard:

 wchar_t *wcstok(wchar_t *restrict ws1, const wchar_t *restrict ws2,
                 wchar_t **restrict ptr);

It would be better to avoid using this function and change your code to use wcschr() directly.

If wcschr is missing too, use this simple implementation:

/* 7.29.4.5 Wide string search functions */
wchar_t *wcschr(const wchar_t *s, wchar_t c) {
    for (;;) {
        if (*s == c)
            return (wchar_t *)s;
        if (*s++ == L'\0')
            return NULL;
    }
}

Here is a standard conformant implementation of wcstok():

wchar_t *wcstok(wchar_t *restrict s1, const wchar_t *restrict s2,
                wchar_t **restrict ptr) {
    wchar_t *p;

    if (s1 == NULL)
        s1 = *ptr;
    while (*s1 && wcschr(s2, *s1))
        s1++;
    if (!*s1) {
        *ptr = s1;
        return NULL;
    }
    for (p = s1; *s1 && !wcschr(s2, *s1); s1++)
        continue;
    if (*s1)
        *s1++ = L'\0';
    *ptr = s1;
    return p;
}
chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • same error :( error LNK2019: unresolved external symbol _wcstok_s referenced in function – koala Jan 18 '16 at 06:55
  • @koala: I modified the answer, you can cancel the downvote and upvote instead `;->`, but I doubt you were the one who downvoted... – chqrlie Jan 20 '16 at 01:30