如何在 C# 中调用 csImageFile.dll (com) 函数

How to call csImageFile.dll (com) functions in c#

我想将经典的 asp / VB 脚本代码部分转换为 C#。代码使用了一个dll csImageFile.dll 专门合并多个tif图像

遗留函数

nPage = 1
Set csImg = Server.CreateObject("csImageFile.Manage")
    do while not rs.eof
        csImg.ReadStream "tif", rs("imagedata").value
        csImg.AddToTif nPage
        nPage = nPage + 1
        rs.movenext
    loop
rs.close

到目前为止,我已经成功地创建了一个 dll 文件的实例(在 c# 中),如下所示

Type aType = Type.GetTypeFromProgID("csImageFile.Manage", true);
Object anObject = Activator.CreateInstance(aType);

我对如何从以下遗留代码调用函数感到困惑

csImg.ReadStream "tif", rs("imagedata").value

提前致谢

创建运行时可调用包装器 (RCW) .NET 程序集可能更容易

tlbimp csImageFile.dll /out:Interop.csImageFile.dll /namespace:csImageFile

然后使用它公开的 COM 类,就好像它们是常规的 .NET 一样:

csImageFile.Manage csImg = new csImageFile.Manage();
csImg.ReadStream("tif", rs("imagedata").value);

但不要忘记在您的项目中包含对 Interop.csImageFile.dll 的引用。