invoke problem

B

Boni

Dear sirs/madam,
I am trying to dynamically invoke assembly. (For some days Tomas helped me
to get it compiled). Now I am so far that I can test if the assembly
invoked. And I get the System.ExecutionEngineException at the time of
Invoke. Apparenty it is because of the cast of parameter 4 or may be because
GC? I tried to pin it but get compiler error, that only pointers can be
pinned.
I would very appreciate any help.
Thanks,

Details:
void AAA::Execute ( Object* Application, int hwndOwner, Object*
(*ContextParams) __gc[], Object* (*ContextParams8) __gc[],
EnvDTE::wizardResult __gc* retval){

Object* arr __gc[];

arr = new Object*[5];



arr[0] =Application;

arr[1] =__box(hwndOwner);

arr[2] =reinterpret_cast<Object*> (*ContextParams);

arr[3] =reinterpret_cast<Object*> (*ContextParams8);

arr[4]=reinterpret_cast<Object*>(retval); //<<This case latter error

arr[4]=NULL; //<<No error, assembly invoked fine!!!

.....

m_Execute->Invoke(m_Instance, arr); //Exception thrown at this place !!!!
 
T

Tomas Restrepo \(MVP\)

Hi Boni,

I am trying to dynamically invoke assembly. (For some days Tomas helped me
to get it compiled). Now I am so far that I can test if the assembly
invoked. And I get the System.ExecutionEngineException at the time of
Invoke. Apparenty it is because of the cast of parameter 4 or may be
because GC? I tried to pin it but get compiler error, that only pointers
can be pinned.
I would very appreciate any help.
Thanks,

Details:
void AAA::Execute ( Object* Application, int hwndOwner, Object*
(*ContextParams) __gc[], Object* (*ContextParams8) __gc[],
EnvDTE::wizardResult __gc* retval){

Object* arr __gc[];

arr = new Object*[5];



arr[0] =Application;

arr[1] =__box(hwndOwner);

arr[2] =reinterpret_cast<Object*> (*ContextParams);

arr[3] =reinterpret_cast<Object*> (*ContextParams8);

arr[4]=reinterpret_cast<Object*>(retval); //<<This case latter error

arr[4]=NULL; //<<No error, assembly invoked fine!!!

Chances are the reinterpret_cast are hosing you here. Try removing the
reinterpret_casts (which are not needed here, anyway). The problem is that,
I believe, the last cast causes the compiler to generate invalid code that
confuses the runtime. Try instead to simply rebox the enumerated value:

arr[0] =Application;
arr[1] =__box(hwndOwner);
arr[2] =*ContextParams;
arr[3] =*ContextParams;
arr[4] = __box(*retval);
 
B

Boni

Dear Tomas,
Thanks, it seems to work this way. But I am wondering why (I am not sure if
it really works correct, even if in this particular case it could be
tolerated). The parameter retaval is a reference to the return value. This
value will be written from inside of the invoked method . But if I box it,
then it is copied to the new object, am I right? If so then I loose return
value of the execute method for the outer execute call. Hope, you understand
what I mean.
Please, could you clarify this. And if I am right, is there any better
solution.
Thanks you for your really great help.
Boni



Tomas Restrepo (MVP) said:
Hi Boni,

I am trying to dynamically invoke assembly. (For some days Tomas helped
me to get it compiled). Now I am so far that I can test if the assembly
invoked. And I get the System.ExecutionEngineException at the time of
Invoke. Apparenty it is because of the cast of parameter 4 or may be
because GC? I tried to pin it but get compiler error, that only pointers
can be pinned.
I would very appreciate any help.
Thanks,

Details:
void AAA::Execute ( Object* Application, int hwndOwner, Object*
(*ContextParams) __gc[], Object* (*ContextParams8) __gc[],
EnvDTE::wizardResult __gc* retval){

Object* arr __gc[];

arr = new Object*[5];



arr[0] =Application;

arr[1] =__box(hwndOwner);

arr[2] =reinterpret_cast<Object*> (*ContextParams);

arr[3] =reinterpret_cast<Object*> (*ContextParams8);

arr[4]=reinterpret_cast<Object*>(retval); //<<This case latter error

arr[4]=NULL; //<<No error, assembly invoked fine!!!

Chances are the reinterpret_cast are hosing you here. Try removing the
reinterpret_casts (which are not needed here, anyway). The problem is
that, I believe, the last cast causes the compiler to generate invalid
code that confuses the runtime. Try instead to simply rebox the enumerated
value:

arr[0] =Application;
arr[1] =__box(hwndOwner);
arr[2] =*ContextParams;
arr[3] =*ContextParams;
arr[4] = __box(*retval);


--
Tomas Restrepo
(e-mail address removed)
http://www.winterdom.com/
....

m_Execute->Invoke(m_Instance, arr); //Exception thrown at this place !!!!
 
T

Tomas Restrepo \(MVP\)

Boni,
Dear Tomas,
Thanks, it seems to work this way. But I am wondering why (I am not sure
if it really works correct, even if in this particular case it could be
tolerated). The parameter retaval is a reference to the return value. This
value will be written from inside of the invoked method . But if I box it,
then it is copied to the new object, am I right? If so then I loose return
value of the execute method for the outer execute call. Hope, you
understand what I mean.

No, you are right, but all this means is that you'll need to copy the value
after the return. If you prefer, you could always create a new local
variable, pass that, and then copy it to the parameter.
 
B

Boni

Thanks Tomas,
I did this workaround (IMHO it is workaround), and it worked. But is there
no general way to pass pointer vales of the arbitrary type to the invoke? .
First the invoke forses me to cast arguments to the Object* and loose type,
and then the compiler can't generate a rigth code to cast the pointer back?
Is it a bug?
Thanks for this fruitfull discussion,
Boni
 
T

Tomas Restrepo \(MVP\)

Hi Boni,
I did this workaround (IMHO it is workaround), and it worked. But is there
no general way to pass pointer vales of the arbitrary type to the invoke?
. First the invoke forses me to cast arguments to the Object* and loose
type, and then the compiler can't generate a rigth code to cast the
pointer back? Is it a bug?

Honestly, I'm not entirely sure. I do think it might be a bug, or perhaps
just a limitation of the type system in the way __gc* are implemented for
value types.
 
Top