See the question and my original answer on StackOverflow

This is not a P/Invoke issue. The arguments are just bad, GetLastError (a) is NTE_KEYSET_NOT_DEF / 0x80090019, which is "The requested provider does not exist.".

Pass null as the provider name parameter to go on, or use a valid provider name.

However, note I would instead define the function like this (ensure unicode, and the first parameter is out, not ref):

[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool CryptAcquireContext(out IntPtr hProv, string pszContainer, string pszProvider, uint dwProvType, uint dwFlags);