我正在为C#类库创建一个CCW组件,这个库包含一些第三方DLL。
此接口和类包含C#类库DLL和第三方DLL的引用。
接口
[ComVisible(true)]
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]//GUID for this interface
[InterfaceType(ComInterfaceType.InterfaceIsDual)]//Enable early as well as late binding
public interface IInterface
{
[DispId(1)]
void Init();
[DispId(2)]
void OpenFile(string FileName);
[DispId(3)]
void Dispose();
[DispId(4)]
THirdPartyDLLClass ThirdPartyMethod();
}接口实现类
[ComVisible(true)]
[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]//GUID for this class
[ClassInterface(ClassInterfaceType.None)]//Don't generate any interface automatically. We will explicitly create one
[ComSourceInterfaces(typeof(IInterface))]//Expose events
[ProgId("CCWTEST.ClassMath")]//Friendly name of the class. Used while creating object without using 'New' keyword
public class ClassMath : IInterface
{
[ComVisible(false)]//Don't expose to COM. Can be used internally.
private ViewerControl objViewerControl = new ViewerControl(); //ref dll class file
[ComVisible(true)]
public void Init()
{
objViewerControl.Init();
}
[ComVisible(true)]
public void OpenFile(string FileName)
{
objViewerControl.OpenFile(FileName);
}
[ComVisible(true)]
public void Dispose()
{
objViewerControl.Dispose();
}
[ComVisible(true)]//
public THirdPartyDLLClass ThirdPartyMethod()
{
return THirdPartyDLLClass.ThirdPartyClassProperty;
}
}JavaScript在经典ASP中
window.onload = onLoad;
function onLoad()
{
try
{
var obj = new ActiveXObject("CCWTEST.ClassMath");
}
catch (e)
{
alert(e.Message);
}
}在将这个DLL注册到gacutil /i并尝试将这些dll访问到我的java脚本代码之后,它会给我一个“未定义”错误。我不知道这会有什么问题。为此,必须将第三方DLL以及C#类库安装到GAC中。
发布于 2013-06-04 22:39:57
尝试使用regsvr32.exe CCWTEST.ClassMath.ocx (您的COM .ocx组件文件)来注册COM组件。
https://stackoverflow.com/questions/16813738
复制相似问题