Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
1,980 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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?
pcsKeyId = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, count_reqd);
if (NULL == pcsKeyId)
{
wprintf(L"**** memory allocation for pcsKeyId failed\n");
goto Cleanup;
}
MultiByteToWideChar(CP_ACP, 0, pbKeyId, ccCount, pcsKeyId, count_reqd);
I have pasted a part of the code. The code is basically reading CHAR string from a FILE into pbKeyId and converting it to WCHAR *pcsKeyId, and then passing the pointer to API NcryptCreatePersistedKey. If I replace pcsKeyId with L"samplekey" then it works.
I have printed pcsKeyId string and it looks OK.
Is your wide character string null terminated? Check with the memory debug pane to be sure the pointer you're passing has 2 bytes of 0 at the end of the string.
Pls also note that I have checked that the pcsKeyId string is zero terminated.
Thanks for your time.
What is the return value from NCryptCreatePersistedKey, presumably its NTE_INVALID_PARAMETER?
Sign in to comment