This documentation is archived and is not being maintained.

ModuleBuilder.CreateGlobalFunctions Method

Complete the global function definitions for this dynamic module.

[Visual Basic]
Public Sub CreateGlobalFunctions()
[C#]
public void CreateGlobalFunctions();
[C++]
public: void CreateGlobalFunctions();
[JScript]
public function CreateGlobalFunctions();

Exceptions

Exception Type Condition
InvalidOperationException This method was called previously.

Remarks

This method should be called when the user is done with defining all of the global functions within this dynamic module. After calling this function, no more new global functions or new global data are allowed.

Example

[Visual Basic, C#, C++] The following sample illustrates the use of CreateGlobalFunctions to create a static global method from a MethodBuilder implemented with DefineGlobalMethod. Note that CreateGlobalFunctions must be called after DefineGlobalMethod has been used to implement at least one global method.

[Visual Basic] 
Dim currentDomain As AppDomain
Dim myAssemblyName As AssemblyName
Dim myMethodBuilder As MethodBuilder = Nothing
Dim myILGenerator As ILGenerator

' Get the current application domain for the current thread.
currentDomain = AppDomain.CurrentDomain
myAssemblyName = New AssemblyName()
myAssemblyName.Name = "TempAssembly"

' Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder = currentDomain.DefineDynamicAssembly(myAssemblyName, _
                                                   AssemblyBuilderAccess.RunAndSave)
' Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")

' Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod("MyMethod1", MethodAttributes.Static _
                                          Or MethodAttributes.Public, Nothing, Nothing)
myILGenerator = myMethodBuilder.GetILGenerator()
myILGenerator.EmitWriteLine("Hello World from global method.")
myILGenerator.Emit(OpCodes.Ret)
' Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions()

[C#] 
AppDomain currentDomain;
AssemblyName myAssemblyName;
MethodBuilder myMethodBuilder=null;
ILGenerator myILGenerator;

// Get the current application domain for the current thread.
currentDomain = AppDomain.CurrentDomain;
myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";

// Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder = 
   currentDomain.DefineDynamicAssembly
               (myAssemblyName, AssemblyBuilderAccess.RunAndSave);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod
     ("MyMethod1",MethodAttributes.Static|MethodAttributes.Public,
           null,null);
myILGenerator = myMethodBuilder.GetILGenerator();
myILGenerator.EmitWriteLine("Hello World from global method.");
myILGenerator.Emit(OpCodes.Ret);
// Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions();

[C++] 
AppDomain* currentDomain;
AssemblyName* myAssemblyName;
MethodBuilder* myMethodBuilder=0;
ILGenerator* myILGenerator;

// Get the current application domain for the current thread.
currentDomain = AppDomain::CurrentDomain;
myAssemblyName = new AssemblyName();
myAssemblyName->Name = S"TempAssembly";

// Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder = currentDomain->DefineDynamicAssembly(
   myAssemblyName,
   AssemblyBuilderAccess::RunAndSave);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule(S"TempModule");

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder->DefineGlobalMethod(
   S"MyMethod1",
   static_cast<MethodAttributes>(MethodAttributes::Static | MethodAttributes::Public),
   0,
   0);
myILGenerator = myMethodBuilder->GetILGenerator();
myILGenerator->EmitWriteLine(S"Hello World from global method.");
myILGenerator->Emit(OpCodes::Ret);
// Fix up the 'TempModule' module .
myModuleBuilder->CreateGlobalFunctions();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

ModuleBuilder Class | ModuleBuilder Members | System.Reflection.Emit Namespace

Show: