Skip to main content

I am calling COM object (written in C#) from COBOL. But when I try to call it, I receive this error:

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. 

This error happens when processing invoke of method GetDate.

I have generated unique GUIDs, also I have COM object signed with generated snk file.

I already done this type of call, and it's working. But with this module, I am missing something.

COBOL code:

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# code

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;
        }
    }
}

#cobolnetexpress
#C
#COM
#c

I am calling COM object (written in C#) from COBOL. But when I try to call it, I receive this error:

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. 

This error happens when processing invoke of method GetDate.

I have generated unique GUIDs, also I have COM object signed with generated snk file.

I already done this type of call, and it's working. But with this module, I am missing something.

COBOL code:

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# code

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;
        }
    }
}

#cobolnetexpress
#C
#COM
#c

Because the method name begins with "Get" it will be treated as a property getter instead of a method unless you change the message type first.

Forcing the COM Message Type

You can override the run-time system default of assuming that all COM messages sent from COBOL beginning "set" or "get" are property set or get operations. You can also force a message which is not prefixed "set" or "get" to be a property set or get. To force the message type, send the message "setDispatchType" to class OLEsup (filename OLEsup):

invoke OLEsup "setDispatchType" using by value lsType 

where:

lsType PIC X(4) COMP-5

value 0 = next message forced to invoke a method value 1 = next message forced to invoke a property set value 2 = next message forced to invoke a property get

The message type is only forced for the next COM message send, after which it reverts to the default behavior until you "setDispatchType" again. Class OLEsup encapsulates several useful functions for COM automation programming, and is fully documented in the  COM Automation Class Library reference.