NcryptCreatePersistedKey C++ in VisualStudio

Vivek Gupta 21 Reputation points

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
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

    Try this allocation:

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

0 additional answers

Sort by: Most helpful