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.Executio nEngineExceptio n 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* (*ContextParams 8) __gc[],
EnvDTE::wizardR esult __gc* retval){
Object* arr __gc[];
arr = new Object*[5];
arr[0] =Application;
arr[1] =__box(hwndOwne r);
arr[2] =reinterpret_ca st<Object*> (*ContextParams );
arr[3] =reinterpret_ca st<Object*> (*ContextParams 8);
arr[4]=reinterpret_ca st<Object*>(ret val); //<<This case latter error
arr[4]=NULL; //<<No error, assembly invoked fine!!!
.....
m_Execute->Invoke(m_Insta nce, arr); //Exception thrown at this place !!!! 6 1350
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.Executio nEngineExceptio n 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* (*ContextParams 8) __gc[], EnvDTE::wizardR esult __gc* retval){
Object* arr __gc[];
arr = new Object*[5]; arr[0] =Application;
arr[1] =__box(hwndOwne r);
arr[2] =reinterpret_ca st<Object*> (*ContextParams );
arr[3] =reinterpret_ca st<Object*> (*ContextParams 8);
arr[4]=reinterpret_ca st<Object*>(ret val); //<<This case latter error
arr[4]=NULL; //<<No error, assembly invoked fine!!!
Chances are the reinterpret_cas t are hosing you here. Try removing the
reinterpret_cas ts (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(hwndOwne r);
arr[2] =*ContextParams ;
arr[3] =*ContextParams ;
arr[4] = __box(*retval);
--
Tomas Restrepo to****@mvps.org http://www.winterdom.com/ ....
m_Execute->Invoke(m_Insta nce, arr); //Exception thrown at this place !!!!
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)" <to****@mvps.or g> schrieb im Newsbeitrag
news:eZ******** ******@TK2MSFTN GP12.phx.gbl... 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.Executio nEngineExceptio n 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* (*ContextParams 8) __gc[], EnvDTE::wizardR esult __gc* retval){
Object* arr __gc[];
arr = new Object*[5]; arr[0] =Application;
arr[1] =__box(hwndOwne r);
arr[2] =reinterpret_ca st<Object*> (*ContextParams );
arr[3] =reinterpret_ca st<Object*> (*ContextParams 8);
arr[4]=reinterpret_ca st<Object*>(ret val); //<<This case latter error
arr[4]=NULL; //<<No error, assembly invoked fine!!!
Chances are the reinterpret_cas t are hosing you here. Try removing the reinterpret_cas ts (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(hwndOwne r); arr[2] =*ContextParams ; arr[3] =*ContextParams ; arr[4] = __box(*retval);
-- Tomas Restrepo to****@mvps.org http://www.winterdom.com/
....
m_Execute->Invoke(m_Insta nce, arr); //Exception thrown at this place !!!!
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.
--
Tomas Restrepo to****@mvps.org
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
"Tomas Restrepo (MVP)" <to****@mvps.or g> schrieb im Newsbeitrag
news:uG******** ******@TK2MSFTN GP12.phx.gbl... 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.
-- Tomas Restrepo to****@mvps.org
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.
--
Tomas Restrepo to****@mvps.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Altland |
last post by:
Here is my basic problem. I have a form that executes a
cpu instensive algorithm occupying the first thread. When
the algorithm is executed another form pops up telling the
user the progress that has been made.
Whenever I attempt to update my frmProgress, the events
are put placed at the end of the thread's queue and
executed after my algorithm is finished. Using the
frmProgress.Label.Invoke method with delagates, I have
heard would fix...
|
by: RickDee |
last post by:
Please help, anybody.
I am trying to write a program so that it can launch an exe file ( which is
also genereated in C# ) and then simulate the button clicking and invoke the
methods inside the exe. The button clicking part is working fine, but I just
cannot get the method call.
Here is my program snippet.
**************************************************************
|
by: Stephen Lamb |
last post by:
I have a background worker thread which I start from a form's HandleCreated
event that makes calls back to the form using Invoke. During shutdown the
form is disposed and the background worker thread is aborted by the system.
How is one to keep the background thread from calling form.Invoke after the
form's window handle has been destroyed? This is definitely happening in my
application. I haven't read anything about this problem in...
|
by: rawCoder |
last post by:
Hi
I am having this InvalidOperationException with message Cannot call Invoke
or InvokeAsync on a control until the window handle has been created
This is raised when i try to invoke a method with arguments
I need to do this as the method is being called Asynchronously from
elsewhere using delegate's BeginInvoke method.
The form is well created/initialized yet the messages states otherwise.
|
by: Paul Tomlinson |
last post by:
Morning all. Let me describe my problem.
Main thread creates child objects and threads and starts them
Timer on the main thread (which only gets activated after the child threads
have started) periodically calls a function Refresh().
This refresh function runs on its own thread and queries our database for
new jobs.
For each job found this timer invokes a delegate on one of the child thread
objects.
I then get the error "Cannot call...
| |
by: Charles Law |
last post by:
Hi guys.
I have two threads: a main thread and a background thread. Lots of stuff
happens in the background thread that means I have to update several (lots)
of controls on a form.
It is quite tiresome to have to write code to call MyControl.Invoke for each
control on the form, along with the delegates that are required for each.
Is there a better way to do this? What I mean is, if I could marshal the
|
by: Pawan Narula via DotNetMonster.com |
last post by:
hi all,
i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly.
now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
|
by: Jeff Stewart |
last post by:
I need a thread to run a subroutine which updates my main form's
progress bar. I've properly marshaled all UI updates to the main UI
thread, and after the main thread starts the worker thread, it waits
for the worker thread to complete by means of a while t.isAlive,
sleep(0) mechanism. But when my worker thread calls my
UpdateProgressBar routine, which calls Me.Invoke, the invoke call
blocks forever. But I can't figure out why the main...
|
by: m.posseth |
last post by:
Hello
does someone know how i can invoke a method in the underlying thread without
the usage of a window handle ??
This works perfect in a form
Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))
|
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= |
last post by:
vs2005, c#
Trying to understand why one way works but the other doesnt.
I have not tried to create a simpler mdi/child/showdialog app for posting
purposes (I think even this would not be so small or simple). I am hoping
the description will generate some ideas I can check out.
PROBLEM:
-----------------
Switching to UI thread using Invoke(), everything seems good.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |