PDA

View Full Version : حرفه ای: نحوه استفاده از DllImport



e-arasteh
دوشنبه 06 مهر 1388, 16:07 عصر
سلام
من میخوام از یه dll که با visual c نوشته شده و اسم توابع اون رو هم می دونم تو c# استفاده کنم.
می دونم که باید از DllImport استفاده کنم اما نمی دونم چطوری.
لطفآ هر کی می دونه راهنماییم کنه
merc:خجالت:

nazaninam
سه شنبه 07 مهر 1388, 08:13 صبح
میتونی Add Refrence کنی مشکلی نداره

kiosksoft
سه شنبه 07 مهر 1388, 08:17 صبح
دوست عزیز dll و تابع خودتان را جایگزین کنید



using System;
using System.Runtime.InteropServices;

class Example
{
// Use DllImport to import the Win32 MessageBox function.

[DllImport ("user32.dll", CharSet = CharSet.Auto)]
public static extern int MessageBox
(IntPtr hWnd, String text, String caption, uint type);

static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox (new IntPtr(0), "Hello, World!", "Hello Dialog", 0);
}
}