المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to call unmanaged C++ DLL in C#.NET



C# Programming
11-12-2009, 04:40 AM
Hi,

I have coded few methods in C++ ********. These methods are to be used in C#.NET . I guess I need to convert the .CPP file(C++ code) into DLL and then import the methods in C#.

I made a Win32 project and converted the exe(C++ code) into unmanaged C++ DLL.

Then I tried to call its method in C#.NET as :

using System.Runtime.InteropServices;

public partial class CDLL : System.Web.UI.Page
{

[DllImport("C:\\Project1\\TestProject\\Debug\\TestProject.dll", EntryPoint = "testMethod", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern void testMethod();

protected void Page_Load(object sender, EventArgs e)
{
testMethod();
}
}

After running the above code i am getting error like : Unable to find an entry point named 'testMethod' in DLL 'C:\Project1\TestProject\Debug\TestProject.dll'. Can any one suggest how to run the above code successfully.


Thanks.