I've got an IIS v6 (Windows Server 2003) web site which uses an old DLL written with unmanaged code. (Aspx, C# using System.Runtime.InteropService to call unmanaged dll) But I've bought a new Windows Server 2008 with IIS7 and the call to unmanaged DLL is not working. In fact my C# code call an unmanaged DLL but the code never ends. It's entering in DLL code (all is working until the "return"; instruction, but it does not return to C# !!). I've tried to configure the application pool (classic mode), the web site properties... but to hard for me.At a time I got the error "IIS Worker Thread stop working"! A sample: ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table runat="server">
asp:TableRow
asp:TableCell
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:TableCell>
</asp:TableRow>
asp:TableRow
asp:TableCell
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
</html>
CS
using System;
using System.Runtime.InteropServices;
public partial class _Default : System.Web.UI.Page
{
[DllImport("MyDLL.dll", EntryPoint = "?get_html@@YAPBDN@Z")]
static extern string get_html(double value);
protected void Button1\_Click(object sender, EventArgs e)
{
Random a = new Random();
Literal1.Text = get\_html(a.NextDouble());
}
}
DLL C++
#include "stdafx.h"
#include "stdio.h"
char myBuffer[MAX_PATH];
__declspec(dllexport) const char * get_html(double value)
{
memset(myBuffer, 0x00, MAX_PATH);
sprintf(myBuffer, "<html><title>Test</title></head><body>Entered value : %.2f<br>Value x2 = %.2f</body></html>", value, value*2);
return myBuffer;
}
With IIS6, when the button is clicked the HTML text is displayed (all is good). With IIS7 nothing is happening !