Question

I am developing an C# libraries, that I need to call from COBOL (unmanaged) code. So I am using COM interop for these purposes.

I have created an layer "ModuleLanucher" that mediates the communication. I have registered this ModuleLanucher library by these commands:

regasm ModuleLanucher.dll /codebase
TLBEXP Modulelanucher.dll

Everything works fine if I have concrete number of parameters in function foo. (mentioned below)

Unfortunately my function foo needs variable number of arguments. This is sketch of my code:

namespace NMSPC
{
   class ModuleLanucher
   {
      void foo(string moduleName, params object[] args)
      {
        //call some dlls with args as parameteres
      }
   }
}

From COBOL code I'm calling COM function foo:

VCCOMServer is class "$OLE$NMSPC.ModuleLanucher"

invoke VCCOMServer "new" returning anInstance
invoke anInstance "foo" using MODULENAME, PARAM01, PARAM02, PARAM03, PARAM04

When I try to call foo method from this COBOL code, I get this error:

Exception 65538 not trapped by the class oleexceptionmanager. Description: "OLE Parameter count mismatch" (8002000E): Invalid number of parameters

Is it even posiible to have COM object function with variable number of arguments?

Thank you for any suggestions

Was it helpful?

Solution

Variable argument lists are not supported by COM. I think the COM part of your method is converted into:

void foo(string moduleName, object[] args) //note the missing params...

To call this method from COBOL, you need to pass an array of objects as the 2nd argument.

If you know the maximum #parms on forehand, an alternative can be that you define your method with this maximum #parms, where you specify them as optional to COM.

Missing parameters are passed as Type.Missing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top