473,503 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MC++ Reflection

Lev
Hi,

I have some code that does reflection on an assembly I load. When I try to
get the attributes on one of the methods implemented in the assembly, the
MC++ version does not return anything. See code below:

Object __gc* memberAttributes[] =
info[MemberIndex]->GetCustomAttributes(__typeof(EntryPointAttribute) ,
false);

info is declared as follows: MemberInfo* info __gc[], and is populated using
GetMembers on the assembly.

However, when I do the following from C#, it all works well:

object[] memberAttributes =
mi.GetCustomAttributes(typeof(EntryPointAttribute) , false);

mi is also a MemberInfo

The problem is that using the MC++, an empty array is returned to me
(needless to say, both the MC++ and the C# is run on the same assembly).

Thanks,
Nov 17 '05 #1
2 1890

--------------------
From: "Lev" <bo*****@hotmail.com>
Subject: MC++ Reflection

Hi,

I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the
MC++ version does not return anything. See code below:

Object __gc* memberAttributes[] =
info[MemberIndex]->GetCustomAttributes(__typeof(EntryPointAttribute) ,
false);

info is declared as follows: MemberInfo* info __gc[], and is populated using GetMembers on the assembly.

However, when I do the following from C#, it all works well:

object[] memberAttributes =
mi.GetCustomAttributes(typeof(EntryPointAttribute) , false);

mi is also a MemberInfo

The problem is that using the MC++, an empty array is returned to me
(needless to say, both the MC++ and the C# is run on the same assembly).

Thanks,


Nothing jumps out at me; this should work. Can you post a more complete
sample, or code that reproduces the problem?

--
Arjun Bijanki, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Nov 17 '05 #2
Lev
// Do some reflection jazz to get the proper type
Type* ExportedTypes __gc[] = m_pAssemblyToExecute->GetExportedTypes();
for(int Index = 0; Index < ExportedTypes->Count; ++Index) {
MemberInfo* info __gc[] = ExportedTypes[Index]->GetMembers(static_cast<BindingFlags>(BindingFlags ::Public | BindingFlags::Instance | BindingFlags::DeclaredOnly));
for(int MemberIndex = 0; MemberIndex < info->Count; MemberIndex++) {
// It is the following line that doesn't seem to work in MC++: At least the MethodAttributes array has length 0
Object __gc* MethodAttributes[] = info[MemberIndex]->GetCustomAttributes(__typeof(EntryPointAttribute) , false);
int AttributeCount = MethodAttributes->Length;
if(0 <= AttributeCount) {
for(int AttributeIndex = 0; AttributeIndex < AttributeCount; AttributeIndex++) {
// TODO
// Would like to be able to do something along the following:
// if(MethodAttributes[AttributeIndex]->GetType() == __typeof(EntryPointAttribute)->FullName) { ... }
// But this may be related to the usage of __typeof above, because this check does not work

if(0 < AttributeCount) {
Object __gc* target = Activator::CreateInstance(ExportedTypes[Index]);
Object* RuntimeArgs __gc[] = {__box(0)};
Object __gc* Result = ExportedTypes[Index]->InvokeMember(info[MemberIndex]->Name,
static_cast<BindingFlags>(BindingFlags::Default | BindingFlags::InvokeMethod),
0,
target,
RuntimeArgs);
}
....

The assembly I am reflecting over is defined as follows:
using RuntimeBridge;
/// <summary>
/// Summary description for Class1.
/// </summary>
public class MyClass : AxaptaBase {
public MyClass() {
Debug.WriteLine("MyClass ctor");
}
[EntryPoint()]
public void Main(Object args) {
try {
StreamWriter sw = new StreamWriter(@"C:\RuntimeBridgeTest.txt");

string ReturnVal = Lookup.TableIdToName(1916);

sw.Write(TableName);
sw.Close();
}
catch(Exception ex) {
}
}

In the C# class above, Lookup is defined in the assembly that does the reflection (so I have a reference back to the assembly that did the reflection and instantiation). When I try to create an instance of the C# class, my MC++ version gets a TargetInvocationException, whereas the C# version, that does exactly the same, does not.

The part to note, for now at least :-), is the fact that the line:
Object __gc* MethodAttributes[] = info[MemberIndex]->GetCustomAttributes(__typeof(EntryPointAttribute) , false);
returns an empty array in MC++ where as the line
object[] memberAttributes = mi.GetCustomAttributes(typeof(EntryPointAttribute) , false);
in C# works perfectly.
"Arjun Bijanki [VCPP MSFT]" <ar****@online.microsoft.com> wrote in message news:Q$**************@cpmsftngxa10.phx.gbl...

--------------------
From: "Lev" <bo*****@hotmail.com>
Subject: MC++ Reflection

Hi,

I have some code that does reflection on an assembly I load. When I try

to
get the attributes on one of the methods implemented in the assembly, the
MC++ version does not return anything. See code below:

Object __gc* memberAttributes[] =
info[MemberIndex]->GetCustomAttributes(__typeof(EntryPointAttribute) ,
false);

info is declared as follows: MemberInfo* info __gc[], and is populated

using
GetMembers on the assembly.

However, when I do the following from C#, it all works well:

object[] memberAttributes =
mi.GetCustomAttributes(typeof(EntryPointAttribute) , false);

mi is also a MemberInfo

The problem is that using the MC++, an empty array is returned to me
(needless to say, both the MC++ and the C# is run on the same assembly).

Thanks,


Nothing jumps out at me; this should work. Can you post a more complete
sample, or code that reproduces the problem?

--
Arjun Bijanki, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
410
by: Daniel Lidström | last post by:
Hi, I've been trying a long time now to generate some XML using MC++ and XmlSerializer. I have a piece of C# code that produces exactly what I want, but I simply can't get the MC++ code to write...
1
1618
by: Philip | last post by:
I am trying to return a string from a mc++ method back to an invoking C# module. In the invoking C# module I have the string defined as.... String strString;.... in mc++ the method definition is...
3
1527
by: Philip | last post by:
I am invoking a mc++ method from C# via an unsafe code block. The reason for the unsafe code block is that I am receiving a int as a return parameter. I am invoking the method with a "ref...
2
2495
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
3
2224
by: Daniel Lidström | last post by:
I have a CS class I wish to write in MC++: public class UnitsCollection : ArrayList { new public Units this { get { return (Units) base; } set { base = value; } } }
1
2419
by: John | last post by:
Hi, I tried to load a mixedmode dll (MC++) with AppDomain.Load(Byte ) in a C# Client. During the Load Process I got the following Exception: System.IO.FileLoadException: Ausnahme von...
0
1588
by: Maxwell | last post by:
Hello, I recently completed a MC++ (VS2003) DLL that wraps a non MFC C++ DLL and need to use it in a MC++ Console Application (no forms/guis of any kind just output to console). Trouble is...
8
2180
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the...
3
5713
by: Bruno LIVERNAIS | last post by:
Hi, We are currently installing a DB2 V9 ESE on a Linux server (RHEL4U4-x86_64). Installation runs successfully on each node. Database user environment is OK and the instance is well created. To...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.