Tuesday, June 12, 2007

How to call Unmanaged DLL from C# application ?

How to call Unmanaged DLL from C# application ?



I develeoped the win32 DLL.

I added the code in the DLL header file as follows :



#ifdef DLLDIR_EX
#define DLLDIR __declspec(dllexport) // export DLL information
#else
#define DLLDIR __declspec(dllimport) // import DLL information
#endif

extern "C"
{
bool DLLDIR GetSysInfo(char* pszSystemName);

};



DLL implementation file I added its defn


How I accessed the DLL in C# ?


VC++ DLL is an Unmanaged code.


This is following way How I accessed that file...


I just copied the .DLL and .LIB files from my DLL project.


and copied it to the debug folder of the C# application


Within C# application



using System.Runtime.InteropServices; // For Interoperability

[DllImport("RemoteSystemDLL.dll")]
public static extern bool GetSysInfo(StringBuilder buf);

and called this GetSysInfo() fn in my application.

// this is the C++ function exposed by the dll

Labels:

0 Comments:

Post a Comment

<< Home