none
Accessing Dll problem

    Question

  • hi

     

        i'm having an Windows application  (exe) main.exe and a dll(contains a windows form)  and i need to call that dll from main.exe.

     

    I want to use late binding

     

    Type t=Type.GetTypeFromProgID("Proj1.class1");

     

    // I'm getting t as null 

    object 0b=Activator.CreateInstance(t);

     

     //Proj1 is my dll Project name   

      

        What should i do??

    Friday, July 20, 2007 6:34 AM

Answers

  • Hi rajashanmugam,

     

    Based on my understanding, the dll(contains a windows form) is a .net assembly, not a COM dll.If I have misunderstood you, please feel free to tell me, thanks.

     

    However, the GetTypeFromProgID method is provided for COM support. ProgIDs are not used in the Microsoft .NET Framework because they have been superseded by the concept of namespace.

     

    If you want to use late binding on a .net type, you can use the following steps:

    1. Load that assembly using Assembly.Load method
    2. Use Assembly.GetType Method to get the Type object with the specified name in the assembly instance
    3. Using Activator.CreateInstance to create an object of that type.

    I hope this can help you!

     

    Thanks!

    Tuesday, July 24, 2007 5:20 AM
  • Hi Anuj007,

     

    I write a code sample for you:

    Code Snippet
    private void btnTest_Click(object sender, EventArgs e)
    {
        Assembly asm = Assembly.Load("FengChen.Common");
        Type formType = asm.GetType("FengChen.Common.FormTest");
        Form formTest = (Form)Activator.CreateInstance(formType);
        formTest.ShowDialog(this);
    }

     

     

    The FengChen.Common is a dll containg a Form type: FromTest, and you can put the dll to be loaded into the folder of the main exe file, and the FormTest is a Form type.

     

    Thanks!

    Friday, August 03, 2007 7:44 AM

All replies

  • Hi rajashanmugam,

     

    Based on my understanding, the dll(contains a windows form) is a .net assembly, not a COM dll.If I have misunderstood you, please feel free to tell me, thanks.

     

    However, the GetTypeFromProgID method is provided for COM support. ProgIDs are not used in the Microsoft .NET Framework because they have been superseded by the concept of namespace.

     

    If you want to use late binding on a .net type, you can use the following steps:

    1. Load that assembly using Assembly.Load method
    2. Use Assembly.GetType Method to get the Type object with the specified name in the assembly instance
    3. Using Activator.CreateInstance to create an object of that type.

    I hope this can help you!

     

    Thanks!

    Tuesday, July 24, 2007 5:20 AM
  • Hi rajashanmugam,

     

    We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.

     

    Thanks!

    Wednesday, July 25, 2007 3:33 AM
  •  

     hi Feng

                  Can i able to show that windows form . when i tried ActiveForm.Show  its throwing an error on that line.

      

    Friday, August 03, 2007 4:27 AM
  • Hi rajashanmuganm,

     

    Could you please clarify "throwing an error on that line"? What error? An exception? You can post it's stack trace and InnterException here.

     

    Thanks!

    Friday, August 03, 2007 5:04 AM
  • Hi Feng,

     

    leave that error

    I'll tell what i want to do, I'm having a winform its an exe and a c# class library(dll) that dll has a winform1 attached to it

    when i click a button on winform exe the winform1 must open ,it must happen at runtime

    Friday, August 03, 2007 5:54 AM
  • hi,

     

    u need to create a dll class having a public function say DisplayForm. This public function should contain the code to display the WIN form of your dll. once done add DLL's reference to your WIN EXE. On Button click, create an instace of DLL class and call the public function 'DisplayForm'. It should work.

     

    thanks

    Friday, August 03, 2007 7:16 AM
  • Hi Anuj007,

     

    I write a code sample for you:

    Code Snippet
    private void btnTest_Click(object sender, EventArgs e)
    {
        Assembly asm = Assembly.Load("FengChen.Common");
        Type formType = asm.GetType("FengChen.Common.FormTest");
        Form formTest = (Form)Activator.CreateInstance(formType);
        formTest.ShowDialog(this);
    }

     

     

    The FengChen.Common is a dll containg a Form type: FromTest, and you can put the dll to be loaded into the folder of the main exe file, and the FormTest is a Form type.

     

    Thanks!

    Friday, August 03, 2007 7:44 AM