473,416 Members | 1,698 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,416 software developers and data experts.

DllImport with ASP.NET ?

Hello,

is it possible to use DllImport to call a DLL in ASP.NET ?
Or is it necessarry that my DLL has to be copied into \System32 ?

My DLL is a native C++ 7.1 DLL (not managed, no COM, no regsvr32) and uses
Assembler to make some math in SSE.
The result is given out as an Int.

Using a C# console app (code below) it work fine & fast.

However, once again ASP.NET refuses to execute my inline ASP.NET code (code
below).

Error Code:

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code. Exception Details:
System.DllNotFoundException: Unable to load DLL (pac.dll).nable to load DLL
(pac.dll).]Stack Trace: [DllNotFoundException: Unable to load DLL
(pac.dll).]

:(

Even the tip out of G00gle to use the full path in DllImport wasn't a
solution.
I've check this on my ISPs websapce and on my local IIS6.

Is the reason for this problem the general extremely over-limited runtime
permission of ASP.NET ?
Can ASP.NET or IIS6 be told to allow DllImport calls to my DLL ?
My ISP is ready to make configuration changes for my case but don't know a
solution, too.

Thx for your opinions !
// Code EXE Console

public class Class1
{
[DllImport("pac.dll")]
public static extern int PaqGetVersion();

public static void Main(string[] args)
{
int t = Class1.PaqGetVersion();
Console.WriteLine(t);

[...]
// CODE ASP.NET

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Runtime.InteropServices" %>
<HTML>
<HEAD>
<Meta Name="CODE_LANGUAGE" Content="C#">

<Script Language=CS Runat=Server>

[DllImport(@"pac.dll")]
public static extern int PaqGetVersion();

void Page_Load(object sender, System.EventArgs e)
{
int i = PaqarGetVersion();
TextBox1.Text = i.ToString();
}
</script>
</HEAD>

[...]
Nov 19 '05 #1
2 10452
"Brian Anderson" <no****@127.0.0.1> wrote in
news:eX**************@TK2MSFTNGP12.phx.gbl:
Hello,

is it possible to use DllImport to call a DLL in ASP.NET ?
Or is it necessarry that my DLL has to be copied into \System32
?

My DLL is a native C++ 7.1 DLL (not managed, no COM, no
regsvr32) and uses Assembler to make some math in SSE.
The result is given out as an Int.

Using a C# console app (code below) it work fine & fast.

However, once again ASP.NET refuses to execute my inline ASP.NET
code (code below).

Error Code:

Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack
trace for more information about the error and where it
originated in the code. Exception Details:
System.DllNotFoundException: Unable to load DLL (pac.dll).nable
to load DLL (pac.dll).]Stack Trace: [DllNotFoundException:
Unable to load DLL (pac.dll).]

:(

Even the tip out of G00gle to use the full path in DllImport
wasn't a solution.
I've check this on my ISPs websapce and on my local IIS6.

Is the reason for this problem the general extremely
over-limited runtime permission of ASP.NET ?
Can ASP.NET or IIS6 be told to allow DllImport calls to my DLL ?
My ISP is ready to make configuration changes for my case but
don't know a solution, too.

Thx for your opinions !
// Code EXE Console

public class Class1
{
[DllImport("pac.dll")]
public static extern int PaqGetVersion();

public static void Main(string[] args)
{
int t = Class1.PaqGetVersion();
Console.WriteLine(t);

[...]
// CODE ASP.NET

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Runtime.InteropServices" %>
<HTML>
<HEAD>
<Meta Name="CODE_LANGUAGE" Content="C#">

<Script Language=CS Runat=Server>

[DllImport(@"pac.dll")]
public static extern int PaqGetVersion();

void Page_Load(object sender, System.EventArgs e)
{
int i = PaqarGetVersion();
TextBox1.Text = i.ToString();
}
</script>
</HEAD>

[...]


Brian,

It could be a security problem, but it seems more likely that
pac.dll is not being found. This is because it is not in the same
folder as your .aspx page dll [*1], nor is it on the system's
search path for dlls [*2].

You stated that using pac.dll's full path in the DllImport
attibute didn't work. Did you get an error message?
If so, what was it?

It's also possible that your application does not have
sufficient permissions to call unmanaged code. You can
find out by running the .aspx page at the end of this article.

If your page cannot call unmanaged code, you will need to have
your ISP configure the .Net security to grant your pages that
permission.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

------------------------------------------------------------

[*1]
ASP.Net compiles each in-lined .aspx page into its own separate
DLL and places it in a temporary directory under c:\windows\microsoft.net.
An example would be:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Tempo rary ASP.NET Files\WebApplication1\64f05764\576f54e7

There's no way to know what name ASP.Net will give this temporary
directory, so you can't put pac.dll there.

In contrast, code in separate code-behind files is compiled into a
single DLL, and that is placed into a \bin folder under the web application,
e.g. c:\inetpub\wwwroot\WebApplication1\bin.

[*2]

Windows uses the algorithm described here to locate DLLs:

http://msdn.microsoft.com/library/de...oadlibrary.asp

------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Security" %>
<%@ Import Namespace="System.Security.Permissions" %>

<html>
<script runat="server">

private static bool CanCallUnmanagedCode
{
get
{
try
{
new SecurityPermission(SecurityPermissionFlag.Unmanage dCode).Demand();
}
catch(SecurityException)
{
return false;
}

return true;
}
}

void Page_Load(Object sender, EventArgs e)
{
if (CanCallUnmanagedCode)
Label1.Text = "This page can call unmanaged code.";
else
Label1.Text = "This page can NOT call unmanaged code.";
}

</script>

<body>
<form runat=server>
<asp:Label id="Label1" Text="Label Control" runat="server"/>
</form>
</body>
</html>
Nov 19 '05 #2
Hello Chris !
You stated that using pac.dll's full path in the DllImport
attibute didn't work. Did you get an error message?
If so, what was it?
It was exactly the same error message (not found).

Will try your tip and report back.

Thx!

---

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16... "Brian Anderson" <no****@127.0.0.1> wrote in
news:eX**************@TK2MSFTNGP12.phx.gbl:
Hello,

is it possible to use DllImport to call a DLL in ASP.NET ?
Or is it necessarry that my DLL has to be copied into \System32
?

My DLL is a native C++ 7.1 DLL (not managed, no COM, no
regsvr32) and uses Assembler to make some math in SSE.
The result is given out as an Int.

Using a C# console app (code below) it work fine & fast.

However, once again ASP.NET refuses to execute my inline ASP.NET
code (code below).

Error Code:

Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack
trace for more information about the error and where it
originated in the code. Exception Details:
System.DllNotFoundException: Unable to load DLL (pac.dll).nable
to load DLL (pac.dll).]Stack Trace: [DllNotFoundException:
Unable to load DLL (pac.dll).]

:(

Even the tip out of G00gle to use the full path in DllImport
wasn't a solution.
I've check this on my ISPs websapce and on my local IIS6.

Is the reason for this problem the general extremely
over-limited runtime permission of ASP.NET ?
Can ASP.NET or IIS6 be told to allow DllImport calls to my DLL ?
My ISP is ready to make configuration changes for my case but
don't know a solution, too.

Thx for your opinions !
// Code EXE Console

public class Class1
{
[DllImport("pac.dll")]
public static extern int PaqGetVersion();

public static void Main(string[] args)
{
int t = Class1.PaqGetVersion();
Console.WriteLine(t);

[...]
// CODE ASP.NET

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Runtime.InteropServices" %>
<HTML>
<HEAD>
<Meta Name="CODE_LANGUAGE" Content="C#">

<Script Language=CS Runat=Server>

[DllImport(@"pac.dll")]
public static extern int PaqGetVersion();

void Page_Load(object sender, System.EventArgs e)
{
int i = PaqarGetVersion();
TextBox1.Text = i.ToString();
}
</script>
</HEAD>

[...]
Brian,

It could be a security problem, but it seems more likely that
pac.dll is not being found. This is because it is not in the same
folder as your .aspx page dll [*1], nor is it on the system's
search path for dlls [*2].

You stated that using pac.dll's full path in the DllImport
attibute didn't work. Did you get an error message?
If so, what was it?

It's also possible that your application does not have
sufficient permissions to call unmanaged code. You can
find out by running the .aspx page at the end of this article.

If your page cannot call unmanaged code, you will need to have
your ISP configure the .Net security to grant your pages that
permission.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

------------------------------------------------------------

[*1]
ASP.Net compiles each in-lined .aspx page into its own separate
DLL and places it in a temporary directory under c:\windows\microsoft.net.
An example would be:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Tempo rary ASP.NET

Files\WebApplication1\64f05764\576f54e7
There's no way to know what name ASP.Net will give this temporary
directory, so you can't put pac.dll there.

In contrast, code in separate code-behind files is compiled into a
single DLL, and that is placed into a \bin folder under the web application, e.g. c:\inetpub\wwwroot\WebApplication1\bin.

[*2]

Windows uses the algorithm described here to locate DLLs:

http://msdn.microsoft.com/library/de...oadlibrary.asp
------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Security" %>
<%@ Import Namespace="System.Security.Permissions" %>

<html>
<script runat="server">

private static bool CanCallUnmanagedCode
{
get
{
try
{
new SecurityPermission(SecurityPermissionFlag.Unmanage dCode).Demand(); }
catch(SecurityException)
{
return false;
}

return true;
}
}

void Page_Load(Object sender, EventArgs e)
{
if (CanCallUnmanagedCode)
Label1.Text = "This page can call unmanaged code.";
else
Label1.Text = "This page can NOT call unmanaged code.";
}

</script>

<body>
<form runat=server>
<asp:Label id="Label1" Text="Label Control" runat="server"/>
</form>
</body>
</html>

Nov 19 '05 #3

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

Similar topics

15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
6
by: Tim Mulholland | last post by:
Whats the correct C# datatype (or marshalling function or something) to use when you're importing a function that has a signature similar to char* FuncA(char c) ? Assuming you know that...
9
by: Ole Christensen | last post by:
I'm trying to make a sort of conditional compilation in my C# code because my app is intended to run on both a Pocket PC and on a normal desktop PC. My code uses a call to an API function that on...
3
by: Mark Jerde | last post by:
I'm sill learning VS .NET 2003, not an expert yet. I'm calling an unmanaged C++ DLL from C# using . When the whole project is done I will be calling a total of 5 C++ DLLs from C#. All the DLLs...
1
by: Brian Anderson | last post by:
Hello, I have a native, C++ console app that uses ~26MB of RAM when it runs. It uses quite a lot of RAM to make some math but will never xceed 26MB. Now I've made a dll out of this code and...
2
by: Ed | last post by:
Hello, dear all, I often see these two import usage in the code. Both are the interface to use the Dll library. I think they are the same. Normally P/Invoke means using the to import the dll....
1
by: kardon33 | last post by:
Let me explain my problem, Im currently trying to use a Perl module that was built for a Windows OS that uses a .dll and .lib file. I have obtained the c header files that the modules were built...
9
by: jjones7947 | last post by:
Am doing a JNI wrap on a C++ API, am using VC7 and Eclipse. In preparation, I created a C++ executable which mimicked the flow of the JNI, i.e. a driver file which called methods in file with methods...
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.