Imprting DLLs into C# program

P

Parrot

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

}
 
I

Ignacio Machin \( .NET/ C# MVP \)

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
 
P

Parrot

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

Ignacio Machin ( .NET/ C# MVP ) said:
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

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Parrot said:
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);

}
 
N

Nicholas Paldino [.NET/C# MVP]

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).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Parrot said:
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

Ignacio Machin ( .NET/ C# MVP ) said:
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

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Parrot said:
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);

}
 
P

Parrot

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

Nicholas Paldino said:
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).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Parrot said:
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

Ignacio Machin ( .NET/ C# MVP ) said:
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

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

}
 
N

Nicholas Paldino [.NET/C# MVP]

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.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Parrot said:
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

Nicholas Paldino said:
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).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Parrot said:
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,


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

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

}
 
P

Parrot

Nicholas Paldino said:
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.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Parrot said:
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

Nicholas Paldino said:
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).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

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,


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

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

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top