Reputation: 65
I would like to link to a C++ dll from my asp.net 3.5 web application and use some of the functions in the code behind. If I create a C# library using DllImport to link to the C++ dll I can then link the C# library to the asp.net application and it seems to work. How do I eliminate the C# library and link directly to the C++ dll?
When I try use DllImport in the C# code behind it is undefined even though the code looks identical to the code in the C# library.
code from the asp.net web app (doesn't work because DllImport gets highlighted as undefined)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.InteropServices;
/// <summary>
/// Summary description for Chat
/// </summary>
public class Chat
{
public Chat()
{
[DllImport("ChatLib.dll")]
public static extern void DisplayHelloFromDLL();
}
}
Upvotes: 1
Views: 707
Reputation: 148150
You probably need to put DllImport
attribute and method declaration out side constructor on class level.
public class Chat
{
[DllImport("ChatLib.dll")]
public static extern void DisplayHelloFromDLL();
public Chat()
{
}
}
Upvotes: 1