You need to pass the address of the pointer into the function. The parameter
lpDecoded
is a temporary one inside the function, so any change to it will disappear when the function returns. Change your code to the following so the buffer address is put in the original pointer:
DWORD Base64Decode(LPCSTR pszEncoded, LPBYTE* lpDecode64) {
DWORD dwBufLen = 0;
CryptStringToBinary(pszEncoded, 0,
CRYPT_STRING_BASE64, NULL, &dwBufLen, NULL, NULL);
*lpDecode64 = (LPBYTE)malloc(dwBufLen);
memset(*lpDecode64, 0x00, dwBufLen);
CryptStringToBinary(pszEncoded, 0,
CRYPT_STRING_BASE64, *lpDecode64,
&dwBufLen, NULL, NULL);
return dwBufLen;
}
CHAR *lpString64 = 0;
LPBYTE lpDecoded = 0;
DWORD dwDecodeLen = 0;
dwDecodeLen = Base64Decode(lpString64, &lpDecoded);