1. 创建一个 C# Class Library ,命名为:ClassLibraryDemo
2. 打开项目的属性,在点选左边的 “Application”(就是第一个tab) , 然后点击 Assembly Information 按钮 ,在弹出的Dialog中, 必须在底部勾上: Make assembly COM-visible !否则 , 这个
3. 创建
使用vs.net的“Vsitual Studio .Net工具”–>Vistual Studio .Net命令提示符,输入 sn -k d:\ClassLibraryDemo.snk回车即创建了
打开项目的属性,点选左边Signing 勾上Sign the assembly 在 Choose a strong name key file:处选择 选择刚才创建的HelloWorld.snk文件
4. 创建类库并编译成
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Runtime.InteropServices;namespaceClassLibraryDemo
{
[ComVisible(true)]public classHello
{public stringWrite()
{return "Hello World";
}
}
}
5. 找到dll文件夹路径
然后使用vs.net的“Vsitual Studio .Net工具”–>Vistual Studio .Net命令提示符
进入该dll文件夹下输入: regasm HelloWorld.dll。
这时候,这个.dll的.net程序集就变成一个标准的Com组件了,但是还不能用,必须让它变成全局Com组件.
这个regasm 实用程序将创建一个类型库并在 Windows 注册表中对其进行注册,以使 PhysServer2.dll 中的类对 COM 客户端可用 .
需要做下面步骤
将程序集添加到全局程序集缓存中
进入提示符窗口,输入: gacutil /I ClassLibraryDemo.dll
这时,你的这个dll就被复制到全局程序集缓存中了.也就是说无论在这个电脑的哪个硬盘上都可以使用此dll组件了.
如果不进行强命名签名,这一步会提示加载失败
$r=new Com("ClassLibraryDemo.Hello");
$s=$r->Write();
echo $s;
?>
问题:到第五步失败了。。后续补充。。。