I am attempting to import a DLL function from a COBOL program using the
DLLImport function but I always get an error that says the Specified module
(dtonsub.dll) cannot be found. I used the link program to determine if
there is a function by the name I am using. I have tried this with both
REALIA and Microfocus COBOL programs and get the same error. Can anyone
enlightened me on what the problem is? Below is my code.
Dave
[DllImport("dtronsub.DLL", EntryPoint = "DTRON1", SetLastError = false,
CharSet = CharSet.Unicode, ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
public static extern void DTRON1(callparm1 c1, callparm2 c2, int x);
public Form1()
{
InitializeComponent();
callparm1 c1 = new callparm1();
c1.filedata = "12345";
callparm2 c2 = new callparm2();
c2.calldata = "abcd";
DTRON1(c1, c2, 0);
}
Ignacio Machin ( .NET/ C# MVP ) - 15 Jan 2008 18:28 GMT
Hi,
You have to know if the dll is a win32 dll (in which case you use P/invoke
as in your code) or maybe it's a COM dll in which case you need to create a
RCW and import it as any other assembly in .NET

Signature
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
>I am attempting to import a DLL function from a COBOL program using the
> DLLImport function but I always get an error that says the Specified
[quoted text clipped - 22 lines]
>
> }
Parrot - 15 Jan 2008 19:15 GMT
Thanks for your reply. Since the COBOL compilers I am using are over 10
years old I will assume they are not win32. How does one create an RCW and
import it into an assembly?
Dave
> Hi,
>
[quoted text clipped - 28 lines]
> >
> > }
Nicholas Paldino [.NET/C# MVP] - 15 Jan 2008 19:41 GMT
There are Win32 dlls older than 10 years. I notice that your exception
says that dtonsub.dll cannot be found (while you are calling dtronsub.DLL).
Are you sure that the DLL is installed on the machine correctly, with all
supporting files? If not, then you have to make sure that it is installed
correctly, and that a call to LoadLibrary passing that dll name will succeed
(as this is what the CLR uses to locate the DLL and make the call).

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Thanks for your reply. Since the COBOL compilers I am using are over 10
> years old I will assume they are not win32. How does one create an RCW
[quoted text clipped - 39 lines]
>> >
>> > }
Parrot - 15 Jan 2008 20:36 GMT
I am able to call this same dll in a program written in C++ which has an
export function. In C++ I have to specify the lib file for the dll in the
linker section of my C++ application. I don't see anywhere in a C#
application that calls for a similar interface. I know that the DLL is
installed and works correctly on the C++ system. I really need to know the
procedure for doing the same thing in C#.
Dave
> There are Win32 dlls older than 10 years. I notice that your exception
> says that dtonsub.dll cannot be found (while you are calling dtronsub.DLL).
[quoted text clipped - 46 lines]
> >> >
> >> > }
Nicholas Paldino [.NET/C# MVP] - 15 Jan 2008 20:50 GMT
Dave,
If you have to link to a library in order to make the call, then you
will have to create your own DLL which exports the signatures that you want
to call, and link to the appropriate library. Then, you call the wrapper
that you generated which exports the functions.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>I am able to call this same dll in a program written in C++ which has an
> export function. In C++ I have to specify the lib file for the dll in
[quoted text clipped - 66 lines]
>> >> >
>> >> > }
Parrot - 15 Jan 2008 22:19 GMT
> Dave,
>
[quoted text clipped - 73 lines]
> >> >> >
> >> >> > }