How do I call a C++(.NET) DLL from an ASP.NET Page?

H

Hoss

Hi
I am an ASP.NET newbie and I have a VB.NET application I am trying to write
in ASP.NET . The problem is that the application calls a DLL written using
VC++.NET . How do I call this DLL from the ASP.NET page? I'd appreciate any
help, as I am stuck for time.
Thanks
 
D

David Browne

Hoss said:
Hi
I am an ASP.NET newbie and I have a VB.NET application I am trying to
write
in ASP.NET . The problem is that the application calls a DLL written using
VC++.NET . How do I call this DLL from the ASP.NET page? I'd appreciate
any
help, as I am stuck for time.

If it's managed C++ then just add a reference to it in your project. If
it's a COM dll, do the same (although different stuff will happen behind the
scenes). If it's an unmanaged, non-COM dll then you need to use P/Invoke.

David
 
H

Hoss

Thankx David, the DLL is managed C++ and I included it as a reference in the
project.
But when I then try to run it, it gives a DLLNotFoundException. What am I
doing wrong?

This is the code:
============================================================================
=============
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalculate.Click
Dim MorphID As Integer, rc As Short

' MorphID's value is returned

rc = LNSearch.InitializeLangData("D:\LangSearch\VB.NET\LNSearch\DataFiles",
MorphID)

End Sub

Public Class LNSearch

Declare Auto Function InitializeLangData Lib
"D:\LangSearch\VC\LNSearchDLL\Release\LNSearchDLL.dll" (ByVal DictPath As
String, ByRef MorphID As Integer) As Short

End Class

============================================================================
=============
 
D

David Browne

Hoss said:
Thankx David, the DLL is managed C++ and I included it as a reference in
the
project.
But when I then try to run it, it gives a DLLNotFoundException. What am I
doing wrong?

This is the code:
============================================================================
=============
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalculate.Click
Dim MorphID As Integer, rc As Short

' MorphID's value is returned

rc =
LNSearch.InitializeLangData("D:\LangSearch\VB.NET\LNSearch\DataFiles",
MorphID)

End Sub

Public Class LNSearch

Declare Auto Function InitializeLangData Lib
"D:\LangSearch\VC\LNSearchDLL\Release\LNSearchDLL.dll" (ByVal DictPath As
String, ByRef MorphID As Integer) As Short

That's P/Invoke. If it's .NET you shouldn'd have to declare the function.
Just add the reference and you should be able to access its functions.

David
 
H

Hoss

Many thanks, it works now.

David Browne said:
That's P/Invoke. If it's .NET you shouldn'd have to declare the function.
Just add the reference and you should be able to access its functions.

David
 
Joined
Sep 15, 2008
Messages
1
Reaction score
0
Marshalling: Using native DLLs in .NET

Please read the following article:
http://blog.rednael.com/2008/08/29/MarshallingUsingNativeDLLsInNET.aspx

It's an in-depth article about how to use a native DLL (or C++ DLL) in your managed .Net code. The article shows which types are interoperable, how to import a DLL, how to pass strings, how to pass structures and how to de-reference pointers.

And C# source code examples are included.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top