NcryptCreatePersistedKey C++ in VisualStudio

Vivek Gupta 21 Reputation points
2022-01-18T14:02:41.88+00:00

API NcryptCreatePersistedKey is not accepting a WCHAR* pointer for the parameter pszKeyName. It crashes . If I give a string literal like L"sample_key" then it works. Can someone pls suggest a workaround?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,410 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,511 questions
{count} votes

Accepted answer
  1. Viorel 111.5K Reputation points
    2022-01-18T19:43:34.507+00:00

    Try this allocation:

    pcsKeyId = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * count_reqd);
    

0 additional answers

Sort by: Most helpful