ModuleBuilder::DefineInitializedData Method (String^, array<Byte>^, FieldAttributes)
Defines an initialized data field in the .sdata section of the portable executable (PE) file.
Assembly: mscorlib (in mscorlib.dll)
public: FieldBuilder^ DefineInitializedData( String^ name, array<unsigned char>^ data, FieldAttributes attributes )
Parameters
- name
-
Type:
System::String^
The name used to refer to the data. name cannot contain embedded nulls.
- data
-
Type:
array<System::Byte>^
The binary large object (BLOB) of data.
- attributes
-
Type:
System.Reflection::FieldAttributes
The attributes for the field. The default is Static.
| Exception | Condition |
|---|---|
| ArgumentException | The length of name is zero. -or- The size of data is less than or equal to zero or greater than or equal to 0x3f0000. |
| ArgumentNullException | name or data is null. |
| InvalidOperationException | CreateGlobalFunctions has been previously called. |
Static is automatically included in attributes.
The data defined by this method is not created until the CreateGlobalFunctions method is called.
Note |
|---|
Starting with the .NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag::ReflectionEmit flag. (See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5 or later. |
The following example uses the DefineInitializedData method to define an initialized data field in the .sdata section of the portable executable (PE) file.
AppDomain^ currentDomain; AssemblyName^ myAssemblyName; // Get the current application domain for the current thread. currentDomain = AppDomain::CurrentDomain; myAssemblyName = gcnew AssemblyName; myAssemblyName->Name = "TempAssembly"; // Define a dynamic assembly in the 'currentDomain'. myAssemblyBuilder = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run ); // Define a dynamic module in "TempAssembly" assembly. myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" ); // Define the initialized data field in the .sdata section of the PE file. array<Byte>^ temp0 = {01,00,01}; FieldBuilder^ myFieldBuilder = myModuleBuilder->DefineInitializedData( "MyField", temp0, (FieldAttributes)(FieldAttributes::Static | FieldAttributes::Public) ); myModuleBuilder->CreateGlobalFunctions();
Available since 1.1
Silverlight
Available since 2.0
