从 COBOL 调用 COM 对象
Call COM object from COBOL
我正在从 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;
}
}
}
我找到了解决方案。方法名称不能以 set 或 get 单词开头。因为当它是时,它被区别对待为 getter 或 setter.
我正在从 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;
}
}
}
我找到了解决方案。方法名称不能以 set 或 get 单词开头。因为当它是时,它被区别对待为 getter 或 setter.