Managed C++ /CLI function CreateInstanceFromAndUnwrap typecast problem.

D

dost

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
 
M

Michael DOUBEZ

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top