• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Visual C# Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Visual C# Developer Center > Visual C# Forums > Visual C# General > Importing a COM type library and adding a few enums
Ask a questionAsk a question
Search Forums:
  • Search Visual C# General Forum Search Visual C# General Forum
  • Search All Visual C# Forums Search All Visual C# Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerImporting a COM type library and adding a few enums

  • Thursday, June 15, 2006 8:23 AMcompilator Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hello, I'm about to create an assembly which contains a converted COM type library, but I'd like to add a few enums on the way. Can I do that? This is the way I've tried so far:

    Object typeLib;

    LoadTypeLibEx(dllPath, RegKind.RegKind_None, out typeLib);

    FileStream fs = new FileStream(@"key.snk", FileMode.Open, FileAccess.Read);

    StrongNameKeyPair keyPair = new StrongNameKeyPair(fs);

    TypeLibConverter converter = new TypeLibConverter();

    ConversionEventHandler eventHandler = new ConversionEventHandler();

    AssemblyBuilder assembly = converter.ConvertTypeLibToAssembly(typeLib, "NewAssembly.dll", TypeLibImporterFlags.PrimaryInteropAssembly, eventHandler, null, keyPair, "NewNamespace", null);

    ModuleBuilder module = assembly.DefineDynamicModule("TempModule", "NewAssembly.dll", true);

    The problem is that I get an ArgumentException "Duplicate file names." when running DefineDynamicModule.

    How can I add enums to my converted COM type library?

    /Chris

     

    • ReplyReply
    • QuoteQuote
     

Answers

  • Thursday, June 15, 2006 9:16 AMMattias SjögrenMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

    Have you tried using GetModule instead of DefineDynamicModule?

     

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Thursday, June 15, 2006 11:42 AMcompilator Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    GetModule returns a Module instead of a ModuleBuilder, so its not really what I'm looking for. Also, the docs for AssemblyBuilder says:

    "Some methods on the base class Assembly such as GetModules and GetLoadedModules will not work correctly when called AssemblyBuilder objects. You can load the defined dynamic assembly and call the methods on the loaded assembly. For example, to ensure that resource modules are included in the returned module list, call GetModules on the loaded Assembly object."

    I'm not quite sure what about GetModules thats not working, but I'm not using it :)

    /Chris

     

    • ReplyReply
    • QuoteQuote
     
  • Thursday, June 15, 2006 1:04 PMMattias SjögrenMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
     compilator wrote:

    GetModule returns a Module instead of a ModuleBuilder, so its not really what I'm looking for.

    Right, but you may be able to cast it to a ModuleBuilder.

    • ReplyReply
    • QuoteQuote
     
  • Thursday, June 15, 2006 2:10 PMcompilator Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    It worked. Scary.
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement