Skip to main content

Problem:

If I have a .Net class and I was to pass a null reference to it from Unmanaged COBOL. How can I do it ?

This is going via .Net COM Interop.

Resolution:

To get this worked as expected you need to pass a COM Variant object with the type set to DISP-E-PARAMNOTFOUND.

This denotes to COM that it is a missing parameters and the .Net Class is given a null object.

The COBOL code to do this is:-

           invoke oleVariant "new" returning mynull

           invoke mynull "getVariantAddress" returning ws-ptr

           set address of lnk-var to ws-ptr

           move DISP-E-PARAMNOTFOUND

                     to VARIANT-VT-SCODE of lnk-var

           invoke ws-dnobj "TestMethod"

                   using by reference string1

                         by reference mynull

                         by value     inta

                         by value     intb

                   returning retval

Attached to this article is a working example showing how to do this.

You will need to run "regasm /tlb /codebase TestCOBOLNull.dll" on the .Net assembly to register it for COM Interop.

Attachments:

COMInteropNulls.zip

Old KB# 3932