【问题标题】:Call COM object from COBOL从 COBOL 调用 COM 对象
【发布时间】:2021-09-14 09:30:01
【问题描述】:

我正在从 COBOL 调用 COM 对象(用 C# 编写)。但是当我尝试调用它时,我收到了这个错误:

Exception 65540 not trapped by the class oleexceptionmanage
Description: "OLE Name not found"                          
(80020006): Unknown name.                                  
                                                           
Hit T to terminate program. Hit any other key to continue. 

在处理 GetDate 方法的调用时会发生此错误。 我已经生成了唯一的 GUID,我还使用生成的 snk 文件对 COM 对象进行了签名。 我已经完成了这种类型的调用,并且它正在工作。但是有了这个模块,我错过了一些东西。

COBOL 代码:

class-control.                                               
  CharacterArray     is class "chararry"                     
  OLESafeArray       is class "olesafea"                     
  FileCrDat is class "$OLE$LLPFileCreateDate.FileCreateDate".
....
05 FileCrDatObj               object reference.
....
invoke FileCrDat "new" returning FileCrDatObj    
invoke FileCrDatObj "GetDate" using w-file-test  
 returning w-file-date                           
end-invoke

                                

C#代码

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace LLPFileCreateDate
{
    [Guid("057DAAB4-8D90-4C5F-922C-F0BEDC7C691C"),
    InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface IFileCreateDate
    {
        [DispId(1)]
        string GetDate(string file);
    }

    [Guid("39DDA4DD-9789-439F-BDD1-620AE0B3B1C5"),
    ClassInterface(ClassInterfaceType.None)]
    public class FileCreateDate : IFileCreateDate
    {
        public FileCreateDate() { }

        public string GetDate(string file)
        {
            DateTime dateCreate = File.GetCreationTime(file);
            string fileDate = dateCreate.ToString();
            return fileDate;
        }
    }
}

【问题讨论】:

    标签: c# com cobol


    【解决方案1】:

    我找到了解决方案。方法名称不能以 set 或 get 单词开头。因为当它存在时,它作为 getter 或 setter 被区别对待。

    【讨论】:

      猜你喜欢
      • 2014-03-05
      • 1970-01-01
      • 2014-02-05
      • 2011-06-20
      • 1970-01-01
      • 2010-11-14
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      相关资源
      最近更新 更多