Importing non-COM dll

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

First attempt at importing a DLL

Here is my class
<code>
public class TIGangProg
{
public TIGangProg(){}

[DllImport("GANG430.dll")]
public static extern int InitCom(string lpszComPort, int IBaudRate);
}
</code>

When I attempt to make a call to InitCom I get a DLLNotFound exception. I
tried added a reference to it, but VS complained it wasn't a valid dll
I tried copying it to the folder where my application is because I thought
it would search there after the DAC, but I still get the same error.

This is a DLL from Texas Instruments and with it comes a sample VB.Net
application using it. So I know it's possible, I just can't read VB code
without becoming suicidal ;)
Actually, I have looked at the VB code and don't see any clues...

Anyone have an idea?
 
Steve,

The GANG430.dll is loaded with LoadLibrary, and it will follow the rules
for locating dlls according to that function.

The easiest way to make sure this works is to make sure that the dll is
in the same location as your .NET assembly.

Hope this helps.
 
When I attempt to make a call to InitCom I get a DLLNotFound exception. I
tried added a reference to it, but VS complained it wasn't a valid dll
I tried copying it to the folder where my application is because I thought
it would search there after the DAC, but I still get the same error.

A couple of things to eliminate:

1) Move the DLL into the root of your C: drive and refer to it there
explicitly, e.g.
[DllImport("c:\\GANG430.dll")]

If that works, then that's all it was - remember that your app will look for
files in different folders depending on whether it's running in Debug mode,
Release mode, or as a fully-compiled executable.

2) If you still get the error, maybe you're missing some support files which
the DLL needs...
Was it written in VB6? If so, do you have the VB6 runtime files installed?
 
Mark Rae said:
When I attempt to make a call to InitCom I get a DLLNotFound exception. I
tried added a reference to it, but VS complained it wasn't a valid dll
I tried copying it to the folder where my application is because I thought
it would search there after the DAC, but I still get the same error.

A couple of things to eliminate:

1) Move the DLL into the root of your C: drive and refer to it there
explicitly, e.g.
[DllImport("c:\\GANG430.dll")]

If that works, then that's all it was - remember that your app will look for
files in different folders depending on whether it's running in Debug mode,
Release mode, or as a fully-compiled executable.

2) If you still get the error, maybe you're missing some support files which
the DLL needs...
Was it written in VB6? If so, do you have the VB6 runtime files installed?

Hi Mark,

That worked, putting it in C:\. I will investigate further, thank you for
your response!

-Steve
 
If that works, then that's all it was - remember that your app will look for
files in different folders depending on whether it's running in Debug mode,
Release mode, or as a fully-compiled executable.
<snip>

This makes sense and is what I tried the first time. For example, I copied
the DLL into obj\Debug thinking that my application would also check in it's
own folder for the DLL, but this fails.
If I tell it to look in c:\ it works.

I feel like I'm missing something... shouldn't it be looking in the folder
where the consuming application is running from?
 
Back
Top