C#:引用Windows Shell界面 [英] C#: Referencing a windows shell interface

查看:294
本文介绍了C#:引用Windows Shell界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的C#,我试图完成一个小方项目我一直在工作,使用的C#代码量小,以帮助在Windows桌面小工具的开发。基本上,我试图实施 IDesktopGadget 接口,这样我就可以使用的 RunGadget 方法。

I'm pretty new to C#, I'm trying to complete a little side project I've been working on that uses a small amount of C# code to assist the development of a Windows Desktop Gadget. Basically, I'm trying to implement the IDesktopGadget interface so that I can use the RunGadget method.

下面是我从阅读有关的类似信息走到这一步,接口:

Here's what I got so far from reading information about similar interfaces:

[ComImport]
[Guid("C1646BC4-F298-4F91-A204-EB2DD1709D1A")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IDesktopGadget
{
    uint RunGadget([MarshalAs(UnmanagedType.LPWStr)] string gadgetPath);
}



不幸的是,我得到一个错误,当我试图从它创建一个对象: 无法创建抽象类或接口GadgetTask.IDesktopGadget的实例

有人能指出我正确的方向,也许帮助我理解我在做什么错在同一时间?

Can someone point me in the right direction and maybe help me understand what I'm doing wrong at the same time?

推荐答案

您确实需要的实现为了使用该接口的DesktopGadget对象。 MS提供了一个标准的COM对象做到这一点在Windows 7中,您可以通过做一些像创建一个实例:

You actually need an implementation of the DesktopGadget object in order to use the interface. MS provide a standard COM object to do it on Windows 7. You can create an instance by doing something like:

Type t = Type.GetTypeFromCLSID(new Guid("924ccc1b-6562-4c85-8657-d177925222b6"));
IDesktopGadget dg = (IDesktopGadget)Activator.CreateInstance(t);

这篇关于C#:引用Windows Shell界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆