How to resolve typelib references when using TypeLibConverter.ConvertTypeLibToAssembly

Im currently trying to use the method TypeLibConverter.ConvertTypeLibToAssembly. Im using the c# example found athttp://msdn2.microsoft.com/en-us/library/k9w7de3e.aspx.

The example works for building a single dll, however the typelib i am converting has multiple references within it which need to be resolved. When the ConversionEventHandler ResolveRef(object typelib) method is called when a reference is found im passed the object typelib (which i dont know what to do with). How do iresolve reference and return a correct assembly?

Any help is appreciated.

Code Example

C#

using System;

using System.Reflection;

using System.Reflection.Emit;

using System.Runtime.InteropServices;

publicclass App

{

private enum RegKind

{

RegKind_Default = 0,

RegKind_Register = 1,

RegKind_None = 2

}
[ DllImport( "oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig =false )]

privatestatic externvoid LoadTypeLibEx( String strTypeLibName, RegKind regKind,

[ MarshalAs( UnmanagedType.Interface )] out Object typeLib );
publicstaticvoid Main()

{

Object typeLib;

LoadTypeLibEx( "Somedll.dll", RegKind.RegKind_None, out typeLib );
if( typeLib ==null )

{

Console.WriteLine( "LoadTypeLibEx failed." );

return;

}
TypeLibConverter converter =new TypeLibConverter();

ConversionEventHandler eventHandler =new ConversionEventHandler();

AssemblyBuilder asm = converter.ConvertTypeLibToAssembly( typeLib, "Interop.Somedll.dll", 0, eventHandler,null,null,null,null );

asm.Save( "Interop.Somedll.dll" );

}

}

publicclass ConversionEventHandler : ITypeLibImporterNotifySink

{

publicvoid ReportEvent( ImporterEventKind eventKind,int eventCode,string eventMsg )

{

// handle warning event here...

}
public Assembly ResolveRef( object typeLib )

{

// resolve reference here and return a correct assembly...

//This is where im not sure how to do it

returnnull;

}

}

[3837 byte] By [Atroa] at [2007-12-25]