Managed C++ /CLI function CreateInstanceFromAndUnwrap typecast problem.

Discussion in 'C++' started by dost, Jun 15, 2011.

  1. dost

    dost Guest

    Hi
    I am facing a problem while using function
    CreateInstanceFromAndUnwrap(....) in my program.

    Problem:
    I do have certain c# dll which i have to load in my c++/cli code.and
    after that i want to call certain function from that assembly. For
    example, I do have a dll(C#) in my C:\ drive.This dll contain a class
    say ABC.
    I want to call certain properties,methods on the object of ABC.

    //my sample code part 1 for AppDomain::CreateInstanceFromAndUnwrap
    //New app domain is created
    AppDomainSetup^ appDomainInfo = gcnew AppDomainSetup();
    appDomainInfo->ApplicationBase = strDefaultPath;//Path of dll(c#)
    AppDomain^ newAppDom =
    AppDomain::CreateDomain(strDomainName,nullptr,appDomainInfo);
    Object^ obj = newAppDom-
    >CreateInstanceFromAndUnwrap(strPath,strClassName );//Line 4

    Type^ tAsmbly = obj->GetType();
    String^ sFullName = tAsmbly->AssemblyQualifiedName;
    PropertyInfo^ pInfo = tAsmbly->GetProperty("AddInType");//property
    not found
    String^ sTypeName = (String^)pInfo->GetValue(obj,nullptr);

    //my sample code part 2 for Assembly::LoadFrom
    Assembly^ asm = Assembly::LoadFrom(strPath);
    Object^ obj = asm->CreateInstance(strClassName);
    Type^ tAsmbly = obj->GetType();
    String^ sFullName = tAsmbly->AssemblyQualifiedName;
    PropertyInfo^ pInfo = tAsmbly->GetProperty("AddInType");//Property
    Found
    String^ sTypeName = (String^)pInfo->GetValue(obj,nullptr);

    //In part 1 i cant typecast the object with the class name because it
    is in only in string format.

    Note:
    In part 1 sFullName is System.MarshalByRefObject, mscorlib,
    Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
    In part 2 sFullName is Actual full name not like above part 2

    Question: I just want to know can I get the Same full name in both
    part. I mean in part 1 I want to get the actual assembly full name. I
    cant type cast it to the desired class so I need some thing by
    reflection I guess.

    Thanks
     
    dost, Jun 15, 2011
    #1
    1. Advertising

  2. On 15 juin, 11:50, dost <> wrote:
    > I am facing a problem while using function
    > CreateInstanceFromAndUnwrap(....) in my program.
    >
    > Problem:
    > I do have certain c# dll which i have to load in my c++/cli code.and
    > after that i want to call certain function from that assembly. For
    > example, I do have a dll(C#) in my C:\ drive.This dll contain a class
    > say ABC.
    > I want to call certain properties,methods on the object of ABC.


    [snip - my eyes are bleeding with all those ^ :) ]

    > Question: I just want to know can I get the Same full name in both
    > part. I mean in part 1 I want to get the actual assembly full name. I
    > cant type cast it to the desired class so I need some thing by
    > reflection I guess.


    Try your question in microsoft.public.dotnet.languages.csharp or in
    microsoft.public.vc.language.

    --
    Michael
     
    Michael DOUBEZ, Jun 15, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. raylopez99
    Replies:
    2
    Views:
    625
    kwikius
    Dec 18, 2006
  2. icedac
    Replies:
    4
    Views:
    764
    James Kanze
    Mar 5, 2008
  3. mr t

    CreateInstanceFromAndUnwrap

    mr t, Mar 7, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    1,268
  4. su
    Replies:
    3
    Views:
    797
    CBFalconer
    Jan 23, 2009
  5. Mark

    typecast function pointer

    Mark, Jan 28, 2012, in forum: C Programming
    Replies:
    9
    Views:
    500
    Keith Thompson
    Jan 30, 2012
Loading...

Share This Page