PRB: Tlbimp.exe Does Not Import Methods in the Module in a Type Library (327099)



The information in this article applies to:

  • Microsoft .NET Framework 1.0

This article was previously published under Q327099

SYMPTOMS

If you have methods that are defined in a module in the library block of an Interface Definition Language (IDL) file, and if you use Tlbimp.exe to import the type library that is generated from this IDL file that is used in Managed world, you discover that Tlbimp does not import the methods in the module.

CAUSE

Methods in the Managed world must be a part of a class because there is no concept of stand-alone methods. Module methods are stand-alone methods. Because there is no stand-alone methods concept in the Managed world, Tlbimp.exe does not import stand-alone methods that are present in the IDL.

RESOLUTION

You can use P/Invoke on the COM DLL to call Module methods.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new .idl file that is named TestModuleMethod.idl.
  2. Copy the following code to TestModuleMethod.idl:
    [
    	uuid(12345678-1234-1234-1234-123456789ABC),	
    ]
    library TestModuleMethod
    {
    	[
    		uuid(12345678-1234-1234-1234-123456789ABD),	
    		dllname("test.dll"),
    	]
    	module ModuleMethod
    	{
    		const long FRAME_COLOR = 0x10;
    		const long WINDOW_COLOR = 0x20;
    		const long BUTTON_COLOR = 0x40;
    	
    		[entry(10)] double pascal Square([in] double x);
    		[entry("MessageBox")] int pascal MsgBox([in] BSTR s);
    	}
    }
    					
  3. Use Midl.exe on TestModuleMethod.idl to create TestModuleMethod.tlb.
        midl.exe testModuleMethod.idl
    					
  4. Use Tlbimp.exe on TestModuleMethod.tlb to create the metadata file that is named InteroptestModuleMethod.dll.
        tlbimp.exe /out:InteroptestModuleMethod.dll testModuleMethod.tlb
    					
  5. Run Ildasm.exe, and then open the metafile that you created in step 4 with Ildasm.

    You may find that the methods in the TestModuleMethod do not appear in the InteroptestModuleMethod.dll.

Modification Type:MajorLast Reviewed:10/15/2003
Keywords:kbprb kbCOMInterop kbnofix KB327099 kbAudDeveloper