Re: I have the same problem

From: Chris Rolon (crolon_at_hotmail.com)
Date: 04/25/04


Date: Sat, 24 Apr 2004 22:42:13 -0700

One note: you should declare the Win32 method to get the last win32 error as
follows

<DllImport("advapi32.dll", SetLasetError := true)> _
 Public Shared Function CryptAcquireContext( _
     ByRef hProv As Integer, _
     ByVal pszContainer As String, _
     ByVal pszProvider As String, _
     ByVal dwProvType As Integer, _
     ByVal dwFlags As Integer) As Boolean
 End Function

If false is returned, you then call
System.Runtime.InteropServices.GetLastWin32Error() to get the error code.
This will ensure that you get the correct error.

One more thing--why don't you use the managed classes for crypto? They are
much easier to use.

Chris Rolon

"jarod tupak via .NET 247" <anonymous@dotnet247.com> wrote in message
news:#qBcB9OKEHA.1264@TK2MSFTNGP12.phx.gbl...
> (Type your message here)
>
> I have the same problem when executing the code below. It returns me a
"126" error from kernel32.
>
> Dim sContainer as String = "sample_example_key"
> Dim sProvider as String = "myprovider"
> If Not (CryptAcquireContext(lHCryptprov, sContainer, sProvider,
PROV_RSA_FULL, 0)) Then
> MsgBox("Error " & GetLastError.ToString & " during
CryptAcquireContext!")
> End If
>
> <DllImport("advapi32.dll")> _
> Public Shared Function CryptAcquireContext( _
> ByRef hProv As Integer, _
> ByVal pszContainer As String, _
> ByVal pszProvider As String, _
> ByVal dwProvType As Integer, _
> ByVal dwFlags As Integer) As Boolean
> End Function
>
> Private Declare Function GetLastError Lib "kernel32" () As Long
>
> --------------------------------
> From: jarod tupak
>
> -----------------------
> Posted by a user from .NET 247 (http://www.dotnet247.com/)
>
> <Id>hpmmaqsoTECdogXS0IdzeA==</Id>



Relevant Pages

  • Re: zebra Printer
    ... ByVal pd As Integer) As Boolean ... Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) As ... bSuccess = myPrinterThreadObj.retVal ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to terminate a running program from another NETCF app
    ... second app that fires the event in the first. ... Public Shared Function CreateEvent(ByVal lpEventAttributes As IntPtr, ... ByVal bManualReset As Boolean, ByVal bInitialState As Boolean, ByVal lpName ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: USB Zebra Printer Communication
    ... Public Shared Function OpenPrinter(ByVal src As String, ... ByVal pd As Long) As Boolean ... Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: USB Zebra Printer Communication
    ... Public Shared Function OpenPrinter(ByVal src As String, ... ByVal pd As Long) As Boolean ... Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: DLLImport Problem with LPCSTR and BOOL
    ... Public Shared Function LaunchRunner(ByVal szUserDisplay As String, ... pbEnabled As Integer) As Boolean ...
    (microsoft.public.dotnet.framework.interop)