C#?е???C++ DLL(P/Invoke)
???????????? ???????[ 2015/2/4 11:46:21 ] ????????C++ C# ???????
??????????????????C++????????о??′?C# ?е???DLL
?????????????????????????????DllImport??????
????????DllImport???????????
????using System.Runtime.InteropServices;
????public class XXXX{
????[DllImport(“MyDLL.dll")]
????public static extern int mySum (int a??int b);
????}
????[DllImport(“MyDLL.dll")]
????public static extern int mySum (int a??int b);
??????????DllImport??????????????????????????????????????????????????????
?????????????
?????????е???? ??? mySum(a??b);??????
?????????????е???: XXXX. mySum(a??b);
????[DllImport(“MyDLL.dll”)]????????????????????????? [DllImport(“MyDLL.dll"?? EntryPoint=" mySum "??CharSet=CharSet.Auto??CallingConvention=CallingConvention.StdCall)] EntryPoint: ????????? DLL ??????????????????й?????????? ??
????CharSet: ????????????????? String ???????? (?????UNICODE)
????CallingConvention?????????????????(???WINAPI)(??α??潲?????
????SetLastError ???????÷????????????????????????? SetLastError Win32 API ???? (C#?????false )
????int ????
[DllImport(“MyDLL.dll")]
//?????int ????
public static extern int mySum (int a1??int b1);
//DLL??????
extern “C” __declspec(dllexport) int WINAPI mySum(int a2??int b2)
{
//a2 b2??????a1 b1
//a2=..
//b2=...
return a+b;
}
//????????int ????
public static extern int mySum (ref int a1??ref int b1);
//DLL??????
extern “C” __declspec(dllexport) int WINAPI mySum(int *a2??int *b2)
{
//?????? a1?? b1
*a2=...
*b2=...
return a+b;
}
????DLL ?貧??char *????
[DllImport(“MyDLL.dll")]
//?????
public static extern int mySum (string astr1??string bstr1);
//DLL??????
extern “C” __declspec(dllexport) int WINAPI mySum(char * astr2??char * bstr2)
{
//???astr2 bstr 2 ??astr1 bstr1???????
return a+b;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11