473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can't reference dll

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());
}
Aug 8 '08 #1
11 4472
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());
}
Aug 8 '08 #2
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.
Aug 8 '08 #3
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.
Aug 8 '08 #4
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.
Aug 8 '08 #5
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.
Aug 8 '08 #6
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.
Aug 8 '08 #7
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.
>
Aug 8 '08 #8
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.

Aug 8 '08 #9
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.


Aug 9 '08 #10
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.
Aug 9 '08 #11
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

Aug 11 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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) {
2
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...
26
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...
13
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...
4
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...
6
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...
3
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*)':...
2
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...
14
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...
22
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.