Thanks for your reply. I can import a C++ dll into my C# program but I have
to use an ordinal number in order to have C# program recognize my entry point
such as "EntryPoint = "#2"; it will not recognize "EntryPoint = "CALL1" for
example.
My biggest problem is that I am trying to import legacy COBOL programs from
Microfocus and my C# program will not even recognize the dll program itself
although this may be masking the fact it can't recognize the entry points. I
use an "EntryPoint # for my COBOL dll but that didn't help. So I imported a
COBOL program into my C++ dll and then had my C# program call C++ and then it
wouldn't recognize the dll just like for the COBOL dlls. So I am totally
confused as to why using COBOL dll's screws everything up. I copied the dll
and lib files into my directory and even tried to just do a call with an
empty function and still not working. I want to be able to access my COBOL
programs through C# but it looks like I am stuck with C++ unless I can figure
out what's going on. Here is my code in C# so far:
[DllImport("c:/development/datatron/datatron/bin/mfcdll.dll", EntryPoint =
"#2", SetLastError = false,
CharSet = CharSet.Unicode, ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
private static extern int CALL1([MarshalAs(UnmanagedType.LPStr)]
String text);
............
string filename = "FILE02";
int ret = CALL1(filename);
My COBOL program has the following code:
LINKAGE SECTION.
01 LINK-FILE PIC X(50).
ENTRY 'CYREAD' using BY REFERENCE LINK-FILE.
....
Also, I am using a 32bit Microfocus compiler from 1998 to create the dll's.
I can't get much help from Microfocus since I am no longer on maintenance.
Nicholas Paldino said:
Dave,
Are you trying to import a regular C++ dll with classes, or a DLL that
exports functions? Or is it a COM dll? If it is a native dll with exported
functions, then you need to create the declarations in C# to make the call
through the P/Invoke layer. If it is a COM dll, then you should set a
reference in your project, and let the IDE create interop dlls for you (or
do it yourself with the TLBIMP utility). If it is a C++ dll with just
regular classes, you are going to have to expose the functionality through
COM (and import it into your project) or create a managed wrapper in C++ and
access that.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Parrot said:
I have tried everything to import a C++ dll into a C# program without
success. I can import the dll into another C++ program but not a C#
program.
I always get the message that it can't find the function in the specified
dll. So it is finding the dll program but it can't find the entry
statements. I know that in C++ environment a lib file is used for
addressing
the entry statements at link time. Obviously, it does not work in a C#
environment since there are no linker variables. Does anyhow have an
example
of importing a C++ dll into a C# program using the DLLexport function?
Dave