1

I'm working on creating a COM callable wrapper for the System.Net.NetworkInformation.Ping class for use in WSH scripts. I've gotten it to compile, but it's not working when called from WSH. I'm not very familiar with COM, so please forgive me if the error is obvious.

Here is the code in my assembly:

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Net;
using System.Net.NetworkInformation;


[assembly: AssemblyVersion("0.0.1.0")]

namespace net.digital_traffic.interop.wrapper
{
[ComVisible(true)]
public interface IPing
{
    //void OnPingCompleted(PingCompletedEventArgs e);
    PingReply Send(IPAddress address);
    PingReply Send(String hostNameOrAddress);
    PingReply Send(IPAddress address, Int32 timeout);
    PingReply Send(String hostNameOrAddress, Int32 timeout);
    PingReply Send(IPAddress address, Int32 timeout, Byte[] buffer);
    PingReply Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer);
    PingReply Send(IPAddress hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options);
    PingReply Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options);
    /*
    void SendAsync(IPAddress address, Object userToken);
    void SendAsync(String hostNameOrAddress, Object userToken);
    void SendAsync(IPAddress address, Int32 timeout, Object userToken);
    void SendAsync(String hostNameOrAddress, Int32  timeout, Object userToken);
    void SendAsync(IPAddress address, Int32 timeout, Byte[] buffer, Object userToken);
    void SendAsync(String hostNameOrAddress, Int32 timeout, Byte[] buffer, Object userToken);
    void SendAsync(IPAddress address, Int32 timeout, Byte[] buffer, PingOptions options, Object userToken);
    void SendAsync(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options, Object userToken);
    void SendAsyncCancel();
    */
}

[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class Ping : System.Net.NetworkInformation.Ping, IPing
{
    public Ping() : base() { }
}

}

Here is the code I'm using to call the assembly in WSH:

var ping1 = new ActiveXObject("net.digital_traffic.interop.wrapper.Ping");

WScript.Echo(ping1.Send("127.0.0.1"));

The above gives me "'ping1' is null or not an object".

1 Answer 1

0

These may help:

Registering my .net assembly for COM interoperability doesn't expose my methods

http://www.csharphelp.com/2006/08/building-com-objects-in-c/

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comsourceinterfacesattribute.aspx

Also, can you give information about how you're specifying your ProgID, and how you're registering your control - can then update the answer with more relevant suggestions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.