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"\\");

...

错误信息:

错误 LNK2019:函数中引用了未解析的外部符号 _wcstok

但。wcslen作品

4

1 回答 1

0

Microsoft 可能会试图强迫您使用wsctok_s而不是标准符合但 non-reentrant wsctok,尤其是在与 Windows 内核链接的设备驱动程序代码中。

如果strtok_s也缺少,则表示用于内核和驱动程序开发的 C 库不完整。您处于托管环境中,标准 C 库的某些部分可能会丢失。

请注意,您没有使用旧原型wcstok():Microsoftwcstok在其 VisualStudio 2015 中更改了原型,以使其符合 C 标准:

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

最好避免使用此功能并更改您的代码以wcschr()直接使用。

如果wcschr也缺少,请使用这个简单的实现:

/* 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;
    }
}

这是一个符合标准的实现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;
}
于 2016-01-18T05:32:11.807 回答