/// <summary> /// This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback See virConnectOpen for notes about environment variables which can have an effect on opening drivers /// </summary> /// <param name="name">URI of the hypervisor</param> /// <param name="auth">Authenticate callback parameters</param> /// <param name="flags">Open flags</param> /// <returns>a pointer to the hypervisor connection or NULL in case of error URIs are documented at http://libvirt.org/uri.html </returns> public static IntPtr OpenAuth(string name, ref ConnectAuth auth, int flags) { // Create a structure that hold cbdata and the callback target OpenAuthManagedCB cbAndUserData = new OpenAuthManagedCB(); cbAndUserData.cbdata = auth.cbdata; cbAndUserData.cbManaged = auth.cb; // Pass the structure as cbdata IntPtr cbAndUserDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbAndUserData)); Marshal.StructureToPtr(cbAndUserData, cbAndUserDataPtr, true); // Create the real ConnectAuth structure, it will call OpenAuthCallbackFromUnmanaged via callback ConnectAuthUnmanaged connectAuth = new ConnectAuthUnmanaged(); connectAuth.cbdata = cbAndUserDataPtr; connectAuth.cb = OpenAuthCallbackFromUnmanaged; connectAuth.CredTypes = auth.CredTypes; return(OpenAuth(name, ref connectAuth, flags)); }
private static extern IntPtr OpenAuth(string name, ref ConnectAuthUnmanaged auth, int flags);
/// <summary> /// This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback See virConnectOpen for notes about environment variables which can have an effect on opening drivers /// </summary> /// <param name="name">URI of the hypervisor</param> /// <param name="auth">Authenticate callback parameters</param> /// <param name="flags">Open flags</param> /// <returns>a pointer to the hypervisor connection or NULL in case of error URIs are documented at http://libvirt.org/uri.html </returns> public static IntPtr OpenAuth(string name, ref ConnectAuth auth, int flags) { // Create a structure that hold cbdata and the callback target OpenAuthManagedCB cbAndUserData = new OpenAuthManagedCB(); cbAndUserData.cbdata = auth.cbdata; cbAndUserData.cbManaged = auth.cb; // Pass the structure as cbdata IntPtr cbAndUserDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbAndUserData)); Marshal.StructureToPtr(cbAndUserData, cbAndUserDataPtr, true); // Create the real ConnectAuth structure, it will call OpenAuthCallbackFromUnmanaged via callback ConnectAuthUnmanaged connectAuth = new ConnectAuthUnmanaged(); connectAuth.cbdata = cbAndUserDataPtr; connectAuth.cb = OpenAuthCallbackFromUnmanaged; connectAuth.CredTypes = auth.CredTypes; return OpenAuth(name, ref connectAuth, flags); }