C# 开发的COM对象注册问题

wxl_pilot 2007-02-01 11:12:15
使用C#(.net 2.0)开发了一个插件后,按照MSDN提示注册插件
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmsrvsdk/htm/registeringnetplugin.asp

regasm 提示 Assembly exported to "**/**/**.tlb" and the type library was registered successfully

但是在注册表下根本就没有找到注册的键值

各位有知情的么?
...全文
628 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxl_pilot 2007-02-01
  • 打赏
  • 举报
回复
看到一个老外的文章http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=113
说可能是因为没有默认参数为空的构造函数造成的
不过我这里已经有了public PreventDownload()
{ }
jinglong6511 2007-02-01
  • 打赏
  • 举报
回复
学习
wxl_pilot 2007-02-01
  • 打赏
  • 举报
回复
@hdt(倦怠)

先使用tlbexp LiveeduPreventDownload.dll
得到了LiveeduPreventDownload.tlb
使用regasm LiveeduPreventDownload.tlb
报错:fail to load (**/**/LiveeduPreventDownload.tlb) because it is not a valid .net assembly
真相重于对错 2007-02-01
  • 打赏
  • 举报
回复
另外想被别的程序看到使用强名称
真相重于对错 2007-02-01
  • 打赏
  • 举报
回复
好像不能直接regasm .net dll
应该先
tlbexp 到出类型库
regasm 注册类型库

wxl_pilot 2007-02-01
  • 打赏
  • 举报
回复
按照MSDN的说明,是进行了注册表操作的,如类中的RegisterFunction方法

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmsrvsdk/htm/registeringnetplugin.asp

我是先将这个编译好的DLL[LiveeduPreventDownload.dll]拷贝到<%systemroot%>/system32/windows media/server/下
再调用regasm LiveeduPreventDownload.dll /tlb
然后就提示我
Assembly exported to "**/**/**.tlb" and the type library was registered successfully

完了注册表里没信息,WINDOWS MEDIA SERVICE里也没发现注册好的插件

另外说明下:
直接使用 regasm LiveeduPreventDownload.dll命令会报错:no types were registered
真相重于对错 2007-02-01
  • 打赏
  • 举报
回复
regasm 注册完默认的inprocsever32值 为 Mscoree.dll ,也就是.net 核心dll
你调用时
时通过

inprocserver32下的
class 和 assembly 键值确定的

liujia_0421 2007-02-01
  • 打赏
  • 举报
回复
也搞不清楚..

帮兄弟顶一把...
wxl_pilot 2007-02-01
  • 打赏
  • 举报
回复
把类文件贴出来吧,大家帮我看看

namespace LiveeduPreventDownload
{
[Guid("13775D86-6049-4958-9308-000CFE07AFDB")]
public class PreventDownload
{
// Statics
public static readonly string GUID;

public PreventDownload()
{ }

static PreventDownload()
{
PreventDownload.GUID = "13775D86-6049-4958-9308-000CFE07AFDB";
}
#region ComRegisterFunctionAttribute
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
RegistryKey regHKLM = Registry.LocalMachine;
RegistryKey regHKCR = Registry.ClassesRoot;
try
{
regHKLM = regHKLM.CreateSubKey("SOFTWARE\\Microsoft\\Windows Media\\Server\\RegisteredPlugins\\Event Notification and Authorization\\{" + PreventDownload.GUID+ "}");
regHKLM.SetValue(null, "四三三");
regHKCR = regHKCR.CreateSubKey("CLSID\\{"+PreventDownload.GUID+"}\\Properties");
regHKCR.SetValue("Name", "四三三");
regHKCR.SetValue("Author", "四三三");
regHKCR.SetValue("CopyRight", "Copyright 2007 . All rights reserved");
regHKCR.SetValue("Description", "四三三");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "注册出现异常!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return;
}
finally
{
regHKLM.Close();
regHKCR.Close();
}
}
#endregion

#region ComUnregisterFunction
[ComUnregisterFunction]
public static void UnRegisterFunction(Type t)
{
RegistryKey regHKLM = Registry.LocalMachine;
RegistryKey regHKCR = Registry.ClassesRoot;
try
{
regHKLM.DeleteSubKey(@"SOFTWARE\Microsoft\Windows Media\Server\RegisteredPlugins\Event Notification and Authorization\{" + PreventDownload.GUID + "}");
regHKCR.DeleteSubKeyTree(@"CLSID\{" + PreventDownload.GUID + "}");
regHKCR.DeleteSubKeyTree("LiveeduPreventDownload.PreventDownload");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "卸载出现异常", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return;
}
finally
{
regHKLM.Close();
regHKCR.Close();
}
}



#endregion
}
椅子 2007-02-01
  • 打赏
  • 举报
回复
这个WindowsMediaServices东西你计算机上装了吗?
hertcloud 2007-02-01
  • 打赏
  • 举报
回复
如果你注册的 插件 提示 成功以后
别的程序 可以使用了
说明是成功的
...
楼主是在regedit中 查找 GUID?
honkerhero 2007-02-01
  • 打赏
  • 举报
回复
据说好像,.net的插件不再写入注册表,它的类是自描述的
咔咔咔西西 2007-02-01
  • 打赏
  • 举报
回复
好多分up
wxl_pilot 2007-02-01
  • 打赏
  • 举报
回复
楼上几位幸运啊
我揭帖结了4次每次告诉我揭帖数大于跟帖数甚么的
晕死
wshuangminlg 2007-02-01
  • 打赏
  • 举报
回复
帮LZ顶
心晴Sunheart 2007-02-01
  • 打赏
  • 举报
回复
来晚了
wxl_pilot 2007-02-01
  • 打赏
  • 举报
回复
搞定了!
右键单击工程--》属性--》应用程序--》点击程序集信息--》最下面的复选框(使程序集Com可见)
揭帖

110,569

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧