I get an error when trying to add a reference to a DLL program from a Realia
COBOL program that is 32 bit. The error message says "Please make sure the
file is accessible and that it is a valid assembly or COM component. I can
access this file using C++ but not C#. My COBOL DLL program passes data by
reference. My coding is shown below:
[DllImport("progcmp1.dll", CharSet=CharSet.Auto, EntryPoint="TRANPROG",
CallingConvention=CallingConvention.StdCall)]
public static extern void TRANPROG(string parms);
private void OnSubmit(object sender, EventArgs e)
{
StringBuilder parms = new StringBuilder("00000000", 87);
TRANPROG(parms.ToString());
} 11 4445
Just a thought:
You might want to try sending your info as a reference also.
[DllImport("progcmp1.dll", CharSet=CharSet.Auto, EntryPoint="TRANPROG",
CallingConvention=CallingConvention.StdCall)]
public static extern void TRANPROG(ref string parms);
private void OnSubmit(object sender, EventArgs e)
{
StringBuilder parms = new StringBuilder("00000000", 87);
string strParams = params.ToString();
TRANPROG(ref strParms);
}
"Parrot" wrote:
I get an error when trying to add a reference to a DLL program from a Realia
COBOL program that is 32 bit. The error message says "Please make sure the
file is accessible and that it is a valid assembly or COM component. I can
access this file using C++ but not C#. My COBOL DLL program passes data by
reference. My coding is shown below:
[DllImport("progcmp1.dll", CharSet=CharSet.Auto, EntryPoint="TRANPROG",
CallingConvention=CallingConvention.StdCall)]
public static extern void TRANPROG(string parms);
private void OnSubmit(object sender, EventArgs e)
{
StringBuilder parms = new StringBuilder("00000000", 87);
TRANPROG(parms.ToString());
}
Parrot wrote:
I get an error when trying to add a reference to a DLL program from a Realia
COBOL program that is 32 bit. The error message says "Please make sure the
file is accessible and that it is a valid assembly or COM component.
You can't add a reference to a DLL to your project unless it's an assembly
or a COM library. If you want to access a DLL that's neither, simply copy it
to an accessible place (the \bin directory of your application, for
example). Do not add it as a reference.
--
J.
Mr. Mostert:
I'm curious: If you don't add a DLL to your project and include it in the
\bin folder instead... how do you call it?
I have no experience in this, but someone at work recently came asking me
how to do something very similar.
"Jeroen Mostert" wrote:
You can't add a reference to a DLL to your project unless it's an assembly
or a COM library. If you want to access a DLL that's neither, simply copy it
to an accessible place (the \bin directory of your application, for
example). Do not add it as a reference.
--
J.
jp2msft wrote:
Mr. Mostert:
I'm curious: If you don't add a DLL to your project and include it in
the \bin folder instead... how do you call it?
The name of the DLL is the first argument to the DllImport attribute, you
can also specify the exported name using the EntryPoint property of
DllImport.
This along with the function signature enables .NET to call the function
through p/invoke.
Thanks for you replies. I added the reference parameter suggested by Jp2msft
and moved my progcmp1.ddl and progcmp1.lib files into my bin directory and I
still get the error message saying 'Unable to load DLL 'progcmp1.dll': The
specified module could not be found. I really want this to work as I want to
call an older COBOL program from C# rather than having to rewrite everything.
What bothers me is that I can call this program ok from a C++ program but
not from C# program. Something got lost in the upgrade to C#. Surely there
are other COBOL programmers who want to do what I want to do. Any other
suggestions?
Dave
"Jeroen Mostert" wrote:
Parrot wrote:
I get an error when trying to add a reference to a DLL program from a Realia
COBOL program that is 32 bit. The error message says "Please make sure the
file is accessible and that it is a valid assembly or COM component.
You can't add a reference to a DLL to your project unless it's an assembly
or a COM library. If you want to access a DLL that's neither, simply copy it
to an accessible place (the \bin directory of your application, for
example). Do not add it as a reference.
--
J.
Did you try Mr. Voigt's suggestion of dropping your DLL into the \bin folder?
I'm guessing if placed "progcmp1.dll" in the bin folder, your P/Invoke call
below might work.
[DllImport("progcmp1.dll", CharSet=CharSet.Auto, EntryPoint="TRANPROG",
CallingConvention=CallingConvention.StdCall)]
public static extern void TRANPROG(string parms);
"Parrot" wrote:
Thanks for you replies. I added the reference parameter suggested by Jp2msft
and moved my progcmp1.ddl and progcmp1.lib files into my bin directory and I
still get the error message saying 'Unable to load DLL 'progcmp1.dll': The
specified module could not be found. I really want this to work as I want to
call an older COBOL program from C# rather than having to rewrite everything.
What bothers me is that I can call this program ok from a C++ program but
not from C# program. Something got lost in the upgrade to C#. Surely there
are other COBOL programmers who want to do what I want to do. Any other
suggestions?
Dave
"Jeroen Mostert" wrote:
Parrot wrote:
I get an error when trying to add a reference to a DLL program from a Realia
COBOL program that is 32 bit. The error message says "Please make sure the
file is accessible and that it is a valid assembly or COM component.
You can't add a reference to a DLL to your project unless it's an assembly
or a COM library. If you want to access a DLL that's neither, simply copy it
to an accessible place (the \bin directory of your application, for
example). Do not add it as a reference.
--
J.
Yes,
I did put my program in the bin folder and I still get an error saying it
can't find the program.
Dave
"jp2msft" wrote:
Did you try Mr. Voigt's suggestion of dropping your DLL into the \bin folder?
I'm guessing if placed "progcmp1.dll" in the bin folder, your P/Invoke call
below might work.
[DllImport("progcmp1.dll", CharSet=CharSet.Auto, EntryPoint="TRANPROG",
CallingConvention=CallingConvention.StdCall)]
public static extern void TRANPROG(string parms);
"Parrot" wrote:
Thanks for you replies. I added the reference parameter suggested by Jp2msft
and moved my progcmp1.ddl and progcmp1.lib files into my bin directory and I
still get the error message saying 'Unable to load DLL 'progcmp1.dll': The
specified module could not be found. I really want this to work as I want to
call an older COBOL program from C# rather than having to rewrite everything.
What bothers me is that I can call this program ok from a C++ program but
not from C# program. Something got lost in the upgrade to C#. Surely there
are other COBOL programmers who want to do what I want to do. Any other
suggestions?
Dave
"Jeroen Mostert" wrote:
Parrot wrote:
I get an error when trying to add a reference to a DLL program from a Realia
COBOL program that is 32 bit. The error message says "Please make sure the
file is accessible and that it is a valid assembly or COM component.
>
You can't add a reference to a DLL to your project unless it's an assembly
or a COM library. If you want to access a DLL that's neither, simply copy it
to an accessible place (the \bin directory of your application, for
example). Do not add it as a reference.
>
--
J.
>
jp2msft wrote:
Did you try Mr. Voigt's suggestion of dropping your DLL into the \bin
folder?
That wasn't actually my suggestion.
My recommended next steps in troubleshooting would be to run Process Monitor
from the sysInternals division of Microsoft and find out where .NET is
looking for the DLL.
IIRC you have an ASP.NET project? If so, I think that code-behind files are
compiled to a different location than precompiled assemblies. If the
DllImport is in a codebehind file try moving it into a class library
project.
If you have a client-side project (not ASP.NET) then the dll needs to go
into the directory containing the executable, either $ProjectDir\bin\Release
or $ProjectDir\bin\Debug, not just bin.
Of course you could also add the directory containing the DLL to your path
(system path for ASP.NET, user path for client-side) or move the DLL into a
directory already listed in the path.
>
I'm guessing if placed "progcmp1.dll" in the bin folder, your
P/Invoke call below might work.
[DllImport("progcmp1.dll", CharSet=CharSet.Auto,
EntryPoint="TRANPROG", CallingConvention=CallingConvention.StdCall)]
public static extern void TRANPROG(string parms);
"Parrot" wrote:
>Thanks for you replies. I added the reference parameter suggested by Jp2msft and moved my progcmp1.ddl and progcmp1.lib files into my bin directory and I still get the error message saying 'Unable to load DLL 'progcmp1.dll': The specified module could not be found. I really want this to work as I want to call an older COBOL program from C# rather than having to rewrite everything. What bothers me is that I can call this program ok from a C++ program but not from C# program. Something got lost in the upgrade to C#. Surely there are other COBOL programmers who want to do what I want to do. Any other suggestions?
Dave
"Jeroen Mostert" wrote:
>>Parrot wrote: I get an error when trying to add a reference to a DLL program from a Realia COBOL program that is 32 bit. The error message says "Please make sure the file is accessible and that it is a valid assembly or COM component.
You can't add a reference to a DLL to your project unless it's an assembly or a COM library. If you want to access a DLL that's neither, simply copy it to an accessible place (the \bin directory of your application, for example). Do not add it as a reference.
-- J.
I change my approach to trying to call a C++ program with no arguments to
pass. I compiled the C++ DLL program and it created a
mydll.intermediate.manifest file whatever the heck that is. I copied the dll
file to my bin directory and in my calling program I inserted the following
code:
[DllImport("c:\\apps\\callprog\\callprog\\bin\\mydl l.dll.intermediate.manifest", EntryPoint = "TRANS", SetLastError = true,
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern void TRANS();
With this code I get the following error: An unhandled exception of type
'System.BadImageFormatException' occurred in callprog.exe
Additional information: An attempt was made to load a program with an
incorrect format. (Exception from HRESULT: 0x8007000B)
So now I can't even call a C++ program with no arguments. What are you
supposed to be able to call from a C# program. I am ready to give up on this
as I can't believe it should be so hard to call one program from another. In
COBOL and C++ its a snap, in C# it seems impossible. Is that progress?
Dave
"Ben Voigt [C++ MVP]" wrote:
jp2msft wrote:
Did you try Mr. Voigt's suggestion of dropping your DLL into the \bin
folder?
That wasn't actually my suggestion.
My recommended next steps in troubleshooting would be to run Process Monitor
from the sysInternals division of Microsoft and find out where .NET is
looking for the DLL.
IIRC you have an ASP.NET project? If so, I think that code-behind files are
compiled to a different location than precompiled assemblies. If the
DllImport is in a codebehind file try moving it into a class library
project.
If you have a client-side project (not ASP.NET) then the dll needs to go
into the directory containing the executable, either $ProjectDir\bin\Release
or $ProjectDir\bin\Debug, not just bin.
Of course you could also add the directory containing the DLL to your path
(system path for ASP.NET, user path for client-side) or move the DLL into a
directory already listed in the path.
I'm guessing if placed "progcmp1.dll" in the bin folder, your
P/Invoke call below might work.
[DllImport("progcmp1.dll", CharSet=CharSet.Auto,
EntryPoint="TRANPROG", CallingConvention=CallingConvention.StdCall)]
public static extern void TRANPROG(string parms);
"Parrot" wrote:
Thanks for you replies. I added the reference parameter suggested
by Jp2msft and moved my progcmp1.ddl and progcmp1.lib files into my
bin directory and I still get the error message saying 'Unable to
load DLL 'progcmp1.dll': The specified module could not be found.
I really want this to work as I want to call an older COBOL program
from C# rather than having to rewrite everything. What bothers me
is that I can call this program ok from a C++ program but not from
C# program. Something got lost in the upgrade to C#. Surely there
are other COBOL programmers who want to do what I want to do. Any
other suggestions?
Dave
"Jeroen Mostert" wrote:
Parrot wrote: I get an error when trying to add a reference to a DLL program from a Realia COBOL program that is 32 bit. The error message says "Please make sure the file is accessible and that it is a valid assembly or COM component.
You can't add a reference to a DLL to your project unless it's an assembly or a COM library. If you want to access a DLL that's neither, simply copy it to an accessible place (the \bin directory of your application, for example). Do not add it as a reference.
-- J.
Parrot wrote:
I change my approach to trying to call a C++ program with no arguments to
pass. I compiled the C++ DLL program and it created a
mydll.intermediate.manifest file whatever the heck that is.
It's just the manifest file (doesn't matter unless you're on Vista). If you
don't have a DLL file, your build either didn't succeed or the file's in
another directory. Check bin\debug and bin\release.
I copied the dll file to my bin directory and in my calling program I
inserted the following code:
[DllImport("c:\\apps\\callprog\\callprog\\bin\\mydl l.dll.intermediate.manifest",
Well, "mydll.dll.intermediate.manifest" is not a DLL. Reference "mydll.dll"
instead.
So now I can't even call a C++ program with no arguments. What are you
supposed to be able to call from a C# program. I am ready to give up on this
as I can't believe it should be so hard to call one program from another. In
COBOL and C++ its a snap, in C# it seems impossible. Is that progress?
If at first you don't succeed, get a better understanding of what you're
doing and try again.
The DLL you reference in the DllImport attribute:
- Must be a valid Win32 DLL file. It must be 32-bit if your executable is
32-bit and 64-bit if your executable is 64-bit.
- Must be reachable when the executable runs. That means it must be in the
executable's search path. See http://msdn.microsoft.com/library/7d83bc18.
Basically, copying the file to the same directory where your executable
resides should do the trick.
- Should not use an absolute path but rely on the search path instead.
Otherwise you tie your application to one particular path.
These rules are not specific to C#. You may have found it easier in C++ and
COBOL because these environments take care of putting the right file in the
right place for you.
--
J.
On Aug 8, 2:57 pm, Parrot <Par...@discussions.microsoft.comwrote:
Thanks for you replies. I added the reference parameter suggested by Jp2msft
and moved my progcmp1.ddl and progcmp1.lib files into my bin directory and I
This says you have a .ddl and .lib file in your bin directory. Do you
have a ".dll" file? As far as I'm aware, .Net cannot p/invoke a .ddl
or .lib file.
If you have the .dll in the correct location and the p/invoke
signature in your C# code correct, then it should just work.
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jan Pieter Kunst |
last post by:
(apologies if this message is a duplicate -- my news server seems to
have problems)
Greetings,
When using PHP 4, this:
// ex. 1
class A {
function A(&$obj) {
|
by: RU |
last post by:
Hi,
I am working on a porting project to port C/C++ application from
unixware C++, AT&T Standard components to g++ with STL on Linux. This
application has been working properly on...
|
by: Dave Hammond |
last post by:
In document "A.html" I have defined a function and within the document
body have included an IFRAME element who's source is document "B.html".
In document "B.html" I am trying to call the function...
|
by: Abe Frohnman |
last post by:
Hello all,
I'm passing a reference to a class into the constructor of a form, like
so: public MyForm(int count, ref Area myArea) {...}
How can I use myArea outside the constructor? Should I...
|
by: z_learning_tester |
last post by:
I'm reading the MS press C# book and there seems to be a contradiction.
Please tell me which one is correct, 1 or 2.
Thanks!
Jeff
1. First it gives the code below saying that it prints 0 then...
|
by: TZ |
last post by:
I have two classes, UIHousehold and WIZEditHousehold (both are
winforms).
UIHousehold creates and shows the WIZEditHousehold (WIZEditHousehold
can't be modal, so UIHousehold doesn't know when...
|
by: Michael Sgier |
last post by:
Hi
i get thousands of messages like below. How shall i resolve that?
Thanks
Mcihael
Release/src/Utility/RawImage.o: In function `CMaskImage::CMaskImage(int,
int, char const*)':...
|
by: jjcp |
last post by:
I would like to say thanks in advance for insight anyone can shed on
this for me.
Long story short from time to time I need to us C++ to take a list of
file and make an index out of them in...
|
by: Monty |
last post by:
Hello,
I have created a solution which has both a web UI and a winform UI, the
latter is just for administrators. The Web UI (a Web Application Project)
and the winform project both...
|
by: clicwar |
last post by:
A simple program with operator overloading and copy constructor:
#include <iostream>
#include <string>
using namespace std;
class Vector {
private:
float x,y;
public:
Vector(float u, float...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |