[Urgent] Import other DLL and use it's function in C#

P

PenguinPig

Dear All

I have register a 3rd's DLL into my pc, and I can create an instance by
using CreateObject in ASP page, eg.
set obj = CreateObject("3rdDLLName");

And it contains several methods such as
string MyMethod(string)
string YourMethod(string)
string NoMethod(string)

Because of some reason, I need using this DLL's function in my C# program,
so I do following
[DllImport("C:\\dll\\3rdDLLName.dll")]
public static extern string MyMethod(string content);

But when I call such method in my program, it throw
Unhandled Exception: System.EntryPointNotFoundException: Unable to find an
entry
point named MyMethod in DLL C:\dll\3rdDLLName.dll

My question is
1. Do the method call in ASP is the EntryPorint of the Dll?
2. How to know the EntryPoint of the Dll?

Many Thanks
 
L

Lau Lei Cheong

You may run "dumpbin /exports C:\dll\3rdDLLName.dll" to see if it has a
properly exported function.

But from your description, it's more likely to be a COM library, which you
can directly "Add reference" if it contains the linking information, or you
can find the correct .tlb file for it.
(if it is the case, you'll see "DllRegisterServer" in one of the exported
functions)
 
I

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

Hi,

There are two way to consume native code and they are different, there is
one called P/invoke which allow you to consume native win DLL, it's what
you tried to do in your code. It does only work for win32 dlls.
The other mechanism is COM interop. this allow you to consume COM objects in
..NET and even as both sounds similar they are WAY different. You consume COM
objets by creating a Runtime Callable Wrapper . It can be done simple by
selecting "Add Reference" in VS and selecting the COM tab. It will generate
all the needed structure for you.
 
P

PenguinPig

Thanks Ignacio Machin~
But how to add reference if i haven't visual studio...
Thanks

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

There are two way to consume native code and they are different, there is
one called P/invoke which allow you to consume native win DLL, it's what
you tried to do in your code. It does only work for win32 dlls.
The other mechanism is COM interop. this allow you to consume COM objects in
.NET and even as both sounds similar they are WAY different. You consume COM
objets by creating a Runtime Callable Wrapper . It can be done simple by
selecting "Add Reference" in VS and selecting the COM tab. It will generate
all the needed structure for you.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



PenguinPig said:
Dear All

I have register a 3rd's DLL into my pc, and I can create an instance by
using CreateObject in ASP page, eg.
set obj = CreateObject("3rdDLLName");

And it contains several methods such as
string MyMethod(string)
string YourMethod(string)
string NoMethod(string)

Because of some reason, I need using this DLL's function in my C# program,
so I do following
[DllImport("C:\\dll\\3rdDLLName.dll")]
public static extern string MyMethod(string content);

But when I call such method in my program, it throw
Unhandled Exception: System.EntryPointNotFoundException: Unable to find an
entry
point named MyMethod in DLL C:\dll\3rdDLLName.dll

My question is
1. Do the method call in ASP is the EntryPorint of the Dll?
2. How to know the EntryPoint of the Dll?

Many Thanks
 
P

PenguinPig

Dear Lau

I cannot locate the file dumpbin, where you got this file?
Also, if i haven't VS.Net, how to reference such dll in my C# code?

ThankS



Lau Lei Cheong said:
You may run "dumpbin /exports C:\dll\3rdDLLName.dll" to see if it has a
properly exported function.

But from your description, it's more likely to be a COM library, which you
can directly "Add reference" if it contains the linking information, or you
can find the correct .tlb file for it.
(if it is the case, you'll see "DllRegisterServer" in one of the exported
functions)

"PenguinPig" <¥øÃZ½Þ¤j·Ý@¤½¥q> ¼¶¼g©ó¶l¥ó·s»D :%[email protected]...
Dear All

I have register a 3rd's DLL into my pc, and I can create an instance by
using CreateObject in ASP page, eg.
set obj = CreateObject("3rdDLLName");

And it contains several methods such as
string MyMethod(string)
string YourMethod(string)
string NoMethod(string)

Because of some reason, I need using this DLL's function in my C# program,
so I do following
[DllImport("C:\\dll\\3rdDLLName.dll")]
public static extern string MyMethod(string content);

But when I call such method in my program, it throw
Unhandled Exception: System.EntryPointNotFoundException: Unable to find an
entry
point named MyMethod in DLL C:\dll\3rdDLLName.dll

My question is
1. Do the method call in ASP is the EntryPorint of the Dll?
2. How to know the EntryPoint of the Dll?

Many Thanks
 
G

Guest

Hi

you can create a proxy class using tlbimp tool.....

tlbimp xx.dll /out:xx_dotnetproxy.dll

here xx.dll is your COM component... now you will get a .net proxy assembly...

Veera.

PenguinPig said:
Thanks Ignacio Machin~
But how to add reference if i haven't visual studio...
Thanks

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

There are two way to consume native code and they are different, there is
one called P/invoke which allow you to consume native win DLL, it's what
you tried to do in your code. It does only work for win32 dlls.
The other mechanism is COM interop. this allow you to consume COM objects in
.NET and even as both sounds similar they are WAY different. You consume COM
objets by creating a Runtime Callable Wrapper . It can be done simple by
selecting "Add Reference" in VS and selecting the COM tab. It will generate
all the needed structure for you.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



PenguinPig said:
Dear All

I have register a 3rd's DLL into my pc, and I can create an instance by
using CreateObject in ASP page, eg.
set obj = CreateObject("3rdDLLName");

And it contains several methods such as
string MyMethod(string)
string YourMethod(string)
string NoMethod(string)

Because of some reason, I need using this DLL's function in my C# program,
so I do following
[DllImport("C:\\dll\\3rdDLLName.dll")]
public static extern string MyMethod(string content);

But when I call such method in my program, it throw
Unhandled Exception: System.EntryPointNotFoundException: Unable to find an
entry
point named MyMethod in DLL C:\dll\3rdDLLName.dll

My question is
1. Do the method call in ASP is the EntryPorint of the Dll?
2. How to know the EntryPoint of the Dll?

Many Thanks
 
L

Lau Lei Cheong

dumpbin is at Program Files\Microsoft Visual Studio .NET
2003\Vc7\bin\dumpbin.exe

Other parts answered by Ignacio and veera. :)

Lau Lei Cheong said:
You may run "dumpbin /exports C:\dll\3rdDLLName.dll" to see if it has a
properly exported function.

But from your description, it's more likely to be a COM library, which you
can directly "Add reference" if it contains the linking information, or
you can find the correct .tlb file for it.
(if it is the case, you'll see "DllRegisterServer" in one of the exported
functions)

PenguinPig said:
Dear All

I have register a 3rd's DLL into my pc, and I can create an instance by
using CreateObject in ASP page, eg.
set obj = CreateObject("3rdDLLName");

And it contains several methods such as
string MyMethod(string)
string YourMethod(string)
string NoMethod(string)

Because of some reason, I need using this DLL's function in my C#
program,
so I do following
[DllImport("C:\\dll\\3rdDLLName.dll")]
public static extern string MyMethod(string content);

But when I call such method in my program, it throw
Unhandled Exception: System.EntryPointNotFoundException: Unable to find
an
entry
point named MyMethod in DLL C:\dll\3rdDLLName.dll

My question is
1. Do the method call in ASP is the EntryPorint of the Dll?
2. How to know the EntryPoint of the Dll?

Many Thanks
 

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