MarshalAsAttribute 类
命名空间: System.Runtime.InteropServices
程序集: mscorlib(在 mscorlib.dll 中)
using System;
using System.Text;
using System.Runtime.InteropServices;
使用场合:
class Program
{
//Applied to a parameter.
public void M1([MarshalAs(UnmanagedType.LPWStr)]String msg) {}
//Applied to a field within a class.
class MsgText {
[MarshalAs(UnmanagedType.LPWStr)]
public String msg = “Hello World”;
}
//Applied to a return value.
[return: MarshalAs(UnmanagedType.LPWStr)]
public String GetMessage()
{
return “Hello World”;
}
static void Main(string[] args)
{ }
}
一个例子:
(MFC导出函数及结构体声明)
extern “C”_declspec(dllexport) BOOL WINAPI Task_AddPatient(CTask* pTask, PatientParam* mPat);
struct PatientParam
{
uns