本文整理汇总了VB.NET中System.Reflection.Emit.UnmanagedMarshal类的典型用法代码示例。如果您正苦于以下问题:VB.NET UnmanagedMarshal类的具体用法?VB.NET UnmanagedMarshal怎么用?VB.NET UnmanagedMarshal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnmanagedMarshal类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Runtime.InteropServices
Public Class Example
Public Shared Sub Main()
Dim myDomain As AppDomain = AppDomain.CurrentDomain
Dim myAsmName As New AssemblyName("EmitMarshalAs")
Dim myAssembly As AssemblyBuilder = _
myDomain.DefineDynamicAssembly(myAsmName, _
AssemblyBuilderAccess.RunAndSave)
Dim myModule As ModuleBuilder = _
myAssembly.DefineDynamicModule(myAsmName.Name, _
myAsmName.Name & ".dll")
Dim myType As TypeBuilder = _
myModule.DefineType("Sample", TypeAttributes.Public)
Dim myMethod As MethodBuilder = _
myType.DefineMethod("Test", MethodAttributes.Public, _
Nothing, new Type() { GetType(String) })
' Get a parameter builder for the parameter that needs the
' attribute, using the HasFieldMarshal attribute. In this
' example, the parameter is at position 0 and has the name
' "arg".
Dim pb As ParameterBuilder = _
myMethod.DefineParameter(0, _
ParameterAttributes.HasFieldMarshal, "arg")
' Get the MarshalAsAttribute constructor that takes an
' argument of type UnmanagedType.
'
Dim ciParameters() As Type = { GetType(UnmanagedType) }
Dim ci As ConstructorInfo = _
GetType(MarshalAsAttribute).GetConstructor(ciParameters)
' Create a CustomAttributeBuilder representing the attribute,
' specifying the necessary unmanaged type. In this case,
' UnmanagedType.BStr is specified.
'
Dim ciArguments() As Object = { UnmanagedType.BStr }
Dim cabuilder As New CustomAttributeBuilder(ci, ciArguments)
' Apply the attribute to the parameter.
'
pb.SetCustomAttribute(cabuilder)
' Emit a dummy method body.
Dim il As ILGenerator = myMethod.GetILGenerator()
il.Emit(OpCodes.Ret)
myType.CreateType()
myAssembly.Save(myAsmName.Name & ".dll")
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Reflection.Emit,代码行数:65,代码来源:UnmanagedMarshal
注:本文中的System.Reflection.Emit.UnmanagedMarshal类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论