CoInitializeSecurity fails in Framework4.0/Win7 but works in Framework3.5/Win7 or in 4.0/WinXp
-
Dear All,I got RPC_E_TOO_LATE(0x80010119) error when call CoInitializeSecurity in VB2010/Framework4.0/win7(x86). But same code works in VB2010/Framework3.5/win7(x86) or in VB2010/Framework4.0/WinXp(x86). The code is below. ' Needed for co-initialize feature (to prevent "Permission Denied" issues) ' When debugging in .NET, turn off the "Enable the Visual Studio hosting process". ' The setting is in Project->Properties->Debug->Enable the Visual Studio hosting process. Imports System.Runtime.InteropServices Module Module1 Const RPC_C_AUTHN_LEVEL_NONE As Integer = 1 Const RPC_C_IMP_LEVEL_ANONYMOUS As Integer = 1 Const EOAC_NONE As Integer = 0 Declare Function CoInitializeSecurity Lib "ole32.dll" ( _ pVoid As IntPtr, cAuthSvc As Int32, asAuthSvc As IntPtr, pReserved1 As IntPtr, _ dwAuthnLevel As UInt32, dwImpLevel As UInt32, _ pAuthList As IntPtr, dwCapabilities As UInt32, pReserved3 As IntPtr) As Integer Sub Main() 'set threading apartment System.Threading.Thread.CurrentThread.SetApartmentState(Threading.ApartmentState.STA) Dim hr As Integer = CoInitializeSecurity( _ IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, _ RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_ANONYMOUS, _ IntPtr.Zero, EOAC_NONE, IntPtr.Zero) MsgBox("CoInitializeSecurity returns: 0x" & (Hex(hr))) End Sub End Module I don't know how can i resolve this. Please help me for this. Thanks in advance.