Live Chat Icon For mobile
Live Chat Icon

How do I use an exported function (extern ‘C’) from a legacy DLL

Platform: WinForms| Category: Win32

Use the DllImport attribute that is a member of the System.Runtime.InteropServices namespace. Assume your exported function found in MyDLL.dll has a signature:

	int MyFunction( LPCTSTR lpCaption, UINT uType);

The code below shows how you can access this function from within C#.

using System; 
using System.Runtime.InteropServices;

class HelloWorld 
{ 
	[DllImport('mydll.dll')] 
 	public int MyFunction(string title, int type); 
 
	public static void Main() 
 	{ 
		int nReturnValue = MyFunction('some string', 14);
  	} 
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.