![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Unmanaged C++ client invoke C# component to Add PSSnapin Failed My DotNetServer.dll component contains the following codes: i used Regasm.exe to register this component as a COM component C# Client Invoke this interface always pass. unmanaged c++ client invoke function "DiagnosticCom()" successful,but failed at "Connect()", Details as below ************************DotNetServer.dll****************************** using System; using System.Runtime.InteropServices; using System.Collections.ObjectModel; using System.Management.Automation; using System.Management.Automation.Runspaces; using Microsoft.SystemCenter.VirtualMachineManager; using Microsoft.SystemCenter.VirtualMachineManager.Remoting; namespace DotNetServer { [InterfaceType(ComInterfaceType.InterfaceIsDual)] [Guid("0E242803-A7E4-4ae4-B6E0-E693090598EB")] public interface IDotComServer { int Connect(string serverName, Int32 tcpPort); string DiagnosticCom(string name); } [ClassInterface(ClassInterfaceType.None)] [ProgId("DotNetServer.DotComServer")] [Guid("F0CD6959-42B4-46f4-B1C9-CC88F626417A")] public class DotComServer : IDotComServer { public DotComServer() { } public int Connect(string serverName, Int32 tcpPort) { RunspaceConfiguration _config = null; _config = RunspaceConfiguration.Create(); PSSnapInException ex = null; //Failed AT _config.AddPSSnapIn("Microsoft.SystemCenter.VirtualMachineManager", out ex); if (ex != null) throw ex; using (Runspace runspace = RunspaceFactory.CreateRunspace(_config)) { runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); Command cmd = new Command("Get-VMMServer"); cmd.Parameters.Add("ComputerName", serverName); cmd.Parameters.Add("TCPPort", tcpPort); Collection<PSObject> result = null; pipeline.Commands.Add(cmd); result = pipeline.Invoke(); pipeline.Stop(); runspace.Close(); if (result != null && result.Count > 0) return 0; } return 1; } public string DiagnosticCom(string name) { return name; } } } ************************************End of DotNetServer******************************* ************************************DotNetClient************************************* <<The following C# codes work well>> using System; namespace DotNetClient { class Program { static void Main(string[] args) { DotNetServer.DotComServer server = new DotNetServer.DotComServer(); string strResult = server.DiagnosticCom("Hello"); int result = server.Connect("WIN-7G3JBRL3JBW.contoso.com", 8100); } } } ************************************Unmanaged C++ Client************************* <<always failed at : spServer->Connect("WIN-7G3JBRL3JBW.contoso.com",8100)>>> #include "stdafx.h" #include <iostream> #import "D:\Projects\SolutionCom\DotNetServer\bin\Debug\DotNetServer.tlb" using namespace std; using namespace DotNetServer; int _tmain(int argc, _TCHAR* argv[]) { HRESULT hr; hr = CoInitialize(NULL); try { IDotComServerPtr spServer; hr = spServer.CreateInstance("DotNetServer.DotComServer"); cout<<spServer->DiagnosticCom("OK")<<endl; // ****************work well********************** long result = spServer->Connect("WIN-7G3JBRL3JBW.contoso.com",8100); // ****************always failed at --->_config.AddPSSnapIn("Microsoft.SystemCenter.VirtualMachineManager", out ex);<----- } catch(_com_error& e) { cout<<e.ErrorMessage()<<endl; ******************Error Message "invalid paramter" } CoUninitialize(); return 0; } *********************************************************** |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Group Policy Client service failed | Vista General | |||
| Component installation failed | Vista installation & setup | |||
| Group policy client server failed logon | General Discussion | |||
| ASP.NET ajax client side framework failed to load | .NET General | |||