473,796 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble using delegate in WndProc

when i use delegate like this:
-----------------
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]
protected override void WndProc(ref Message m)
{

delegate_ReplyF romDataProcess = new
PrepareDelegate _ReplyFromDataP rocess(ReplyFro mDataProcess);
delegate_ReplyF romDataProcess. BeginInvoke(m, null, null);

}

delegate void PrepareDelegate _ReplyFromDataP rocess(Message m);
private void ReplyFromDataPr ocess(Message m)
{
IntPtr pnt = dp.OnReply(UInt 32.Parse(m.WPar am.ToString()),
Int32.Parse(m.L Param.ToString( )));
}

-----------------

i met the error:
*********

{"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."}

*********
but if i changed the code like this:

--------------
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]
protected override void WndProc(ref Message m)
{
IntPtr pnt = dp.OnReply(UInt 32.Parse(m.WPar am.ToString()),
Int32.Parse(m.L Param.ToString( )));
}
--------------

everything is ok,so why and how i can handle this,thanks

Mar 1 '06 #1
2 4112

sh***********@g mail.com wrote:
when i use delegate like this:

-----------------
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]
protected override void WndProc(ref Message m)
{
delegate_ReplyF romDataProcess = new
PrepareDelegate _ReplyFromDataP rocess(ReplyFro mDataProcess);
delegate_ReplyF romDataProcess. BeginInvoke(m, null, null);
}

delegate void PrepareDelegate _ReplyFromDataP rocess(Message m);
private void ReplyFromDataPr ocess(Message m)
{
IntPtr pnt = dp.OnReply(UInt 32.Parse(m.WPar am.ToString()),
Int32.Parse(m.L Param.ToString( )));
}

-----------------

i met the error:
*********

{"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."}

*********
but if i changed the code like this:

--------------
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]
protected override void WndProc(ref Message m)
{
IntPtr pnt = dp.OnReply(UInt 32.Parse(m.WPar am.ToString()),
Int32.Parse(m.L Param.ToString( )));
}
--------------

everything is ok,so why and how i can handle this,thanks


I think the problem is that Delegate.BeginI nvoke causes the called
method to run on a different thread, and it looks like you can't get at
the Message across a thread boundary. You might try changing the
delegate signature to use the *members* of Message, and explicitly pass
those, so that the delegate doesn't have to access the Message itself.
ie instead of taking (Message m), the delegate takes (IntPtr LParam,
Int32 Msg, IntPtr WParam). Might work.

--
Larry Lard
Replies to group please

Mar 1 '06 #2
hi,
i've tried the way you said ,but the error is the same

------

delegate void PrepareDelegate _ReplyFromDataP rocess(UInt32 wParam, Int32
lParam);
private void ReplyFromDataPr ocess(UInt32 wParam, Int32 lParam)
{
}

-----

[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]
protected override void WndProc(ref Message m)
{
delegate_ReplyF romDataProcess = new
PrepareDelegate _ReplyFromDataP rocess(ReplyFro mDataProcess);

delegate_ReplyF romDataProcess. BeginInvoke(UIn t32.Parse(m.WPa ram.ToString()) ,
Int32.Parse(m.L Param.ToString( )), null, null);

base.WndProc(re f m);

}
-----------

can u handle this,thanks

Larry Lard wrote:
sh***********@g mail.com wrote:
when i use delegate like this:

-----------------
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]
protected override void WndProc(ref Message m)
{
delegate_ReplyF romDataProcess = new
PrepareDelegate _ReplyFromDataP rocess(ReplyFro mDataProcess);
delegate_ReplyF romDataProcess. BeginInvoke(m, null, null);
}

delegate void PrepareDelegate _ReplyFromDataP rocess(Message m);
private void ReplyFromDataPr ocess(Message m)
{
IntPtr pnt = dp.OnReply(UInt 32.Parse(m.WPar am.ToString()),
Int32.Parse(m.L Param.ToString( )));
}

-----------------

i met the error:
*********

{"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."}

*********
but if i changed the code like this:

--------------
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]
protected override void WndProc(ref Message m)
{
IntPtr pnt = dp.OnReply(UInt 32.Parse(m.WPar am.ToString()),
Int32.Parse(m.L Param.ToString( )));
}
--------------

everything is ok,so why and how i can handle this,thanks


I think the problem is that Delegate.BeginI nvoke causes the called
method to run on a different thread, and it looks like you can't get at
the Message across a thread boundary. You might try changing the
delegate signature to use the *members* of Message, and explicitly pass
those, so that the delegate doesn't have to access the Message itself.
ie instead of taking (Message m), the delegate takes (IntPtr LParam,
Int32 Msg, IntPtr WParam). Might work.

--
Larry Lard
Replies to group please


Mar 1 '06 #3

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

Similar topics

1
1772
by: Terminal882003 | last post by:
Hi, I have a problem in my application(C#) if I using RichTextBox to continuously display a series of text messages (using method AppendText()). When application is running, it will stop at some point (randomly), the error message is: ********************************* System.NullReferenceException: Object reference not set to an instance of an object.
9
3976
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
3
3627
by: cdj | last post by:
Hi all, I've got a picturebox on a form, and a save button. When I go to save, the app craps out with the following error: ================== An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll
11
1992
by: Eric | last post by:
hi, I want to convert a C# class into COM, so that I can use the class in C++. The codes compile and link well. But when I run the program, I got a exception. Any comment is welcome. Thanks in advance. Eric
2
2887
by: Phuff | last post by:
I have an application that should run in the system tray while open. It is supposed to be open at all times and I need it to dissapear when the "X" button is pushed on the form...but without closing the app. I've tried overriding the closing event > Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As > System.ComponentModel.CancelEventArgs) Handles MyBase.Closing > 'Don't close this form > e.Cancel = True
3
2860
by: Siv | last post by:
Hi, A little while ago I wrote a small program that allowed the user to view products from a database. The database holds the details of the products which can be viewed via a form and additionally pictures of the product are stored in an images subfolder and the database holds the file name of the relevant picture. The user can then click a button to display the picture in a pop-up window and also another button to email the potential...
4
12027
by: Rob | last post by:
I've constructed a user control inherited from ListView so I can handle and respond to scrolling events (to keep 2 listviews scrolling in sync). My user control includes an Overrides of WndProc (I've attached the code at the end of this mail). Is it possible to 'disable' this override until I need it - it's just when I populate the ListViews this sub is called repeatadly. What I'd like to do is populate the listviews and then 'enable'...
11
1888
by: Snowbleach | last post by:
Hello, I am having trouble with the following console application. I am using delegates/event to make a clock raise an alarm when a certain amount of time has been reached. The following compiles, but code does nothing else then to produce an endless loop. Any help would be greatly appreciated, I'm probably overlooking something silly. Regards, Arjen.
6
4500
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog opens, but when I click to change the folder, the exception occurs pointing to FileSaveDialog1.ShowDialog(). The exception also indicates some problem with system.drawing.dll. The exception text is: "Attempted to read or write protected memory. This is often an
0
9685
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, 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...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
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,...
0
10021
tracyyun
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...
0
9061
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, 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...
0
6802
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();...
0
5454
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...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3744
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.