2

For an application, we use UPnP to discover and register devices/service(we have server and client part).

For the discovery, we used the http://managedupnp.codeplex.com/ which worked very well.

To register, we did found some library, but they were VERY buggy(intel open source library), and we now want to use the COM component and make a small c# abstraction on it.

I found some documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa381805(v=vs.85).aspx but I've got a problem.

This library contains only interfaces, and I can't see how I can get an instance of it. And I can't find any example/documentation.

So, does anybody knows how to register a device/service with this COM component?

Thank you!

EDIT:

I tried to generate a C# dll:

midl /target NT51 /tlb "C:\upnphost.tlb" "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\upnphost.idl"
tlbimp upnphost.tlb

But after importing this generated dll, I only got the same interface than before :/. Am I on the right way, how should I do that?

4

1 回答 1

2

Once you've done the midl + tlbimp, you can just write this kind of code, as the tlbimp should have create a class (UPnPRegistrarClass) and an interface IUPnPRegistrar that the underlying COM class implements:

IUPnPRegistrar registrar = (IUPnPRegistrar)new UPnPRegistrarClass();
registrar.RegisterDevice(
    File.ReadAllText("DimmerDevice-Desc.xml"),
    "My.Class",
    "MyInitString",
    "MyContainerId",
    Path.GetFullPath("."),
    3200);

Note: for this to work, download the UPnP device registration sample on your disk, and copy the two XML description files to the current execution path. You also must implement a COM Object with a progid ("My.Class" that works because the RegisterDevice call will indeed instantiate this object to build an identifier. You can do that with .NET.

Device and service description formats are available here: UPnP™ Device Architecture 1.1. In the Windows world, there are some extra restrictions specified here: Creating a Device Description (Windows)

于 2013-02-05T13:02:36.423 回答