Calling CryptStringToBinaryA(...) from Crypt32.dll

 

Hello,

I am working on some code that receives a BASE64 string that I need to decode using the CryptStringToBinaryA() function from Crypt32.dll WinAPI. I am also using the CryptBinaryToStringA() function which works fine but only because I copied it's usage from another piece of code. See below what I have put together. Any help with the CryptStringToBinaryA() function would be greatly appreciated.

#define CRYPT_STRING_BASE64             0x00000001 // 100% Correct
#define CRYPT_STRING_BINARY             0x00000002 // Incorrect? I guessed

#import "Crypt32.dll"
    int CryptBinaryToStringA(string src, int cbBinary, int dwFlags, string pszString, int& pcchString[]); // 100% Correct
    string CryptStringToBinaryA(string pszString, int cbBinary, int dwFlags, string response, int pcbBinary, int pdwSkip, int pdwFlags); // I put the vars together for this import. Almost certainly it is wrong.
#import

int start()
{
   // Encode to BASE64 .. all working just fine
   string StartString= "123456";
   string base64 = "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
   string decoded = "";
   int outLen[1];
   outLen[0] = StringLen(base64);
   CryptBinaryToStringA(StartString,StringLen(sNumber),CRYPT_STRING_BASE64,base64,outLen);

   // The variable base64 is now an encoded string

   // Decode from BASE64. This is where I am having the trouble. Pretty sure the function import is 
   // incorrect and the usage below is incorrect too but could not find any documentation that suited mql4.
   // At this point MT4 advises "function 'CryptStringToBinaryA' call from dll 'Crypt32.dll' critical error"

   CryptStringToBinaryA(base64 , StringLen(base64), CRYPT_STRING_BINARY, decoded, 0, 0, 0);
   Alert(decoded); // this should output the original StartString variable but the CryptStringToBinaryA(...) function crashes when called
}
Reason: