Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Unmanaged C++ client invoke C# component to Add PSSnapin Failed

Reply
 
Old 11-27-2008   #1 (permalink)
William.Ding


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46