Importing DLL functions in c# code
22,162
Please have a look at the following article on Code Project for an in depth explanation
A small sample from the linked article is as shown below
To call a function, say methodName
int __declspec(dllexport) methodName(int b)
{
return b;
}
Include the class library (MethodNameLibrary.dll) containing the above method as shown below in c#
class Program
{
[DllImport(@"c:\MethodNameLibrary.dll")]
private static extern int methodName(int b);
static void Main(string[] args)
{
Console.WriteLine(methodName(3));
}
}
Author by
Amit Agrawal
Updated on July 09, 2022Comments
-
Amit Agrawal almost 2 years
I have a DLL, whose functions i want to use in my c# code Here are the functions of that DLL :
extern "C" { __declspec(dllimport) const char* __stdcall ZAJsonRequestA(const char *szReq); __declspec(dllimport) const wchar_t* __stdcall ZAJsonRequestW(const wchar_t *szReq); __declspec(dllimport) const BSTR __stdcall ZAJsonRequestBSTR(BSTR sReq); }
Can anyone tell me how to use it in c# project, as this dll seems to be in other language ?