Click here to Skip to main content
15,913,854 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: low language programing using c Pin
Christian Graus19-Jan-07 8:13
protectorChristian Graus19-Jan-07 8:13 
AnswerRe: low language programing using c Pin
Christian Graus21-Jan-07 0:36
protectorChristian Graus21-Jan-07 0:36 
QuestionCalling unmanaged methods with a managed delegate? Pin
Xpnctoc18-Jan-07 13:17
Xpnctoc18-Jan-07 13:17 
AnswerRe: Calling unmanaged methods with a managed delegate? Pin
Christian Graus18-Jan-07 13:41
protectorChristian Graus18-Jan-07 13:41 
AnswerRe: Calling unmanaged methods with a managed delegate? Pin
User 58385218-Jan-07 13:53
User 58385218-Jan-07 13:53 
AnswerRe: Calling unmanaged methods with a managed delegate? Pin
Mark Salsbery18-Jan-07 15:07
Mark Salsbery18-Jan-07 15:07 
GeneralRe: Calling unmanaged methods with a managed delegate? Pin
Xpnctoc18-Jan-07 15:24
Xpnctoc18-Jan-07 15:24 
QuestionDynamic event delegate and the 'this' pointer Pin
Peter JC18-Jan-07 12:55
Peter JC18-Jan-07 12:55 
I create dynamic event delegates (see code at end of question), which call a common method. When an event is fired, my dynamic method is called and in turn calls the common method.
My problem is that when in the common method the 'this' pointer is meaningless (as if it thinks its a static), so I can't access members of my class. I have a temporary work around where I build in the members to the dynamic method and pass them to the common method! however it still breaks in the debugger and I have to <continue> but gives the desired result.
There is something not right with my dynamic method and if anyone can put me on the right track then that would be greatly appreciated.

Thanks
Peter.

void EventHandler::CreateDynamicEventHandler()
{

System::Type ^ eventClass = m_eventSource->GetTarget()->GetType();

// Get event info and the type of delegate.
array<system::type^>^ args;
EventInfo ^ eventInfo = eventClass->GetEvent(m_eventName);
System::Type ^ tDelegate = eventInfo->EventHandlerType;
MethodInfo^ invoke = tDelegate->GetMethod( "Invoke" );


// The generated delegate will call a standard method (CommonEventHandler)
// to pass the events data onto Jade. Get the method info for that method.
array<system::type^>^ commonArgs = {System::String::typeid, array<system::object^>::typeid};
MethodInfo ^ methodInfo = EventHandler::typeid->GetMethod("CommonEventHandler", commonArgs);


// Create dynamic method
array<system::type^> ^ paramTypes = GetDelegateParameterTypes(tDelegate);
DynamicMethod ^ dynamicMethod = gcnew DynamicMethod("Dyna",
nullptr,
paramTypes,
::EventHandler::typeid);

// Generate method body
ILGenerator ^ ilGen = dynamicMethod->GetILGenerator();

// Create a local variable 'args'
int paramCount = paramTypes->Length;
LocalBuilder ^ localObj = ilGen->DeclareLocal(array<system::object^>::typeid);

// create object array of proper length
ilGen->Emit(OpCodes::Ldc_I4, paramCount);
ilGen->Emit(OpCodes::Newarr, System::Object::typeid);
ilGen->Emit(OpCodes::Stloc_0);

// Now put all arguments in the object array
for (System::Int32 i= 0; i<paramcount; i++)
="" {
="" system::byte="" b="System::Convert::ToByte(i);
" ilgen-="">Emit(OpCodes::Ldloc_0); // Local variable - the array
ilGen->Emit(OpCodes::Ldc_I4, i); // Index into array
ilGen->Emit(OpCodes::Ldarg_S, b); // Value to save is in bth argument to this method
if (paramTypes[i]->IsValueType)
ilGen->Emit(OpCodes::Box, paramTypes[i]); // Box value types
ilGen->Emit(OpCodes::Stelem_Ref, i);
}

// Call common method after pushing parameters
ilGen->Emit(OpCodes::Ldarg_0); // 'this' ptr (required for instance calls)
ilGen->Emit(OpCodes::Ldstr, m_eventName); // Just to help with debugging!
ilGen->Emit(OpCodes::Ldloc_0);
ilGen->EmitCall(OpCodes::Call, methodInfo, nullptr);
ilGen->Emit(OpCodes::Ret);

// Create delegate (Also completes dynamic method build)
System::Delegate ^ del = dynamicMethod->CreateDelegate(tDelegate);

// Add delegate to event's invocation list
MethodInfo ^ addHandler = eventInfo->GetAddMethod();
array<system::object^> ^ addHandlerArgs = {del};
addHandler->Invoke(m_eventSource->GetTarget(), addHandlerArgs);

}
QuestionForm1 to Form2, and Form2 to Form1 Pin
GSanchezDigitalProfile18-Jan-07 5:25
GSanchezDigitalProfile18-Jan-07 5:25 
AnswerRe: Form1 to Form2, and Form2 to Form1 Pin
Christian Graus18-Jan-07 10:09
protectorChristian Graus18-Jan-07 10:09 
GeneralRe: Form1 to Form2, and Form2 to Form1 Pin
GSanchezDigitalProfile18-Jan-07 22:13
GSanchezDigitalProfile18-Jan-07 22:13 
GeneralRe: Form1 to Form2, and Form2 to Form1 Pin
Christian Graus19-Jan-07 8:11
protectorChristian Graus19-Jan-07 8:11 
QuestionHow to Marshall (DLL::MyClass) object in a VS2005-C# App? Pin
jayart18-Jan-07 4:49
jayart18-Jan-07 4:49 
AnswerRe: How to Marshall (DLL::MyClass) object in a VS2005-C# App? Pin
led mike18-Jan-07 5:05
led mike18-Jan-07 5:05 
GeneralRe: How to Marshall (DLL::MyClass) object in a VS2005-C# App? Pin
jayart18-Jan-07 5:14
jayart18-Jan-07 5:14 
QuestionInsert dataset content into a local database table Pin
Vinod Moorkkan16-Jan-07 21:01
Vinod Moorkkan16-Jan-07 21:01 
AnswerRe: Insert dataset content into a local database table Pin
led mike18-Jan-07 5:07
led mike18-Jan-07 5:07 
QuestionRe-Compiling to utilize on different machines? New to CLI C++ Pin
bobbreton16-Jan-07 15:51
bobbreton16-Jan-07 15:51 
AnswerRe: Re-Compiling to utilize on different machines? New to CLI C++ Pin
Christian Graus17-Jan-07 9:30
protectorChristian Graus17-Jan-07 9:30 
QuestionOWL->MFC->C# Pin
StevenS_Dev16-Jan-07 10:37
StevenS_Dev16-Jan-07 10:37 
AnswerRe: OWL->MFC->C# Pin
Mark Salsbery16-Jan-07 10:46
Mark Salsbery16-Jan-07 10:46 
GeneralRe: OWL-&gt;MFC-&gt;C# Pin
StevenS_Dev16-Jan-07 12:36
StevenS_Dev16-Jan-07 12:36 
QuestionHow to run project in c++ in .net Pin
Imran Khan Pathan15-Jan-07 20:01
Imran Khan Pathan15-Jan-07 20:01 
QuestionRe: How to run project in c++ in .net Pin
prasad_som15-Jan-07 20:27
prasad_som15-Jan-07 20:27 
AnswerRe: How to run project in c++ in .net Pin
Imran Khan Pathan15-Jan-07 20:46
Imran Khan Pathan15-Jan-07 20:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.