Problem:
When attempting to generate COBOL calling C#, the regasm command gets error "cannot bind to server <DLL name>"
Resolution:
The following steps will allow Cobol to call a .net dll.
1. Create a new VS.NET class library and add a simple method that returns a string.
2. Strongly name the assembly
Use the sn.exe utility to create a key for the assembly (sn.exe -k TestKey.snk)
3. Add TestKey.snk to the VS.NET project and modify the AssemblyKeyFile attribute in
AssemblyInfo.cs to have the filepath to TestKey.snk
i.e. (last three lines in the AssemblyInfo.cs)
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile(@"C:\\Net Express\\Base\\DEMO\\omdmap\\TestKey.snk")]
[assembly: AssemblyKeyName("")]
4. Compile the VS.NET class library
5. Use regasm to register the assembly as a COM object
run regasm from the command line like this:
regasm <your_assem_name>.dll /tlb /codebase /verbose
/tlb - tell regasm to create a type library from the assembly
/codebase - we use the switch to add an extra key to the registry that points to the assembly location.
An alternative to this is to install the assembly into the GAC, but this is fine for now
/verbose - provides some extra info from the regasm tool
6. Create a MicroFocus Cobol project
$set ooctrl( p)
class-control.
*>All classes to be used in this program must be defined here
Startup is class "$OLE$InteropTest.Startup".
WORKING-STORAGE SECTION.
01 StartupObj object reference.
01 Text-Message pic x(30).
PROCEDURE DIVISION.
Main-Process SECTION.
PERFORM Program-Initialize
PERFORM Program-Body
PERFORM Program-Terminate
.
Program-Initialize SECTION.
.
Program-Body SECTION.
invoke Startup "new" returning StartupObj.
invoke StartupObj "TextMessage" returning Text-Message.
Program-Terminate SECTION.
STOP RUN
.
9. Animate the app.