473,770 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mpossible strange behaviour with sendmessage (make no sense at all)

Hi,

I use sendMessage to retrieve information from another application.

For some obscur reasons, my code work only in a button click event and
nowhere else in my application. I mean I get unexpected result
depending where the code is placed in my application ?!?!?!?!?

Here is my code:
=============== =============== ==
//retrieve all line in a win32 multiline textbox
IntPtr
NbOfLines=SendM essage(1050958, EM_GETLINECOUNT ,IntPtr.Zero,In tPtr.Zero);
string CtrlContent="";
// MessageBox.Show ("Uncomment this line and everything work....");
for (int cnt=0;cnt<(int) NbOfLines;cnt++ )
{
StringBuilder textBuffer = new StringBuilder() ;
int NbOfChars=SendM essage(1050958, EM_GETLINE,cnt, textBuffer);
CtrlContent+=te xtBuffer.ToStri ng();
}
MessageBox.Show ("Content="+Ctr lContent);
The preceding code placed in a button click event work
perfectly....bu t the same code in a TreeView afterSelect event is not
working at all, the content is always empty without any reasons...

if I put a messagebox before the loop, everything work
perfectly.....T his is totally weird is anybody can explain what is
going on???

This non logic behaviour is a ***MAJOR PROBLEM*** in my application I
really need to find a way to fix this..

Thanks!
Jul 19 '08 #1
4 1683
On Jul 19, 7:29*am, michelqa <miche...@yahoo .cawrote:
Hi,

I use sendMessage to retrieve information from another application.

For some obscur reasons, my code work only in a button click event and
nowhere else in my application. *I mean I get unexpected result
depending where the code is placed in my application ?!?!?!?!?

Here is my code:
=============== =============== ==
//retrieve all line in a win32 multiline textbox
IntPtr
NbOfLines=SendM essage(1050958, EM_GETLINECOUNT ,IntPtr.Zero,In tPtr.Zero);
string CtrlContent="";
// MessageBox.Show ("Uncomment this line and everything work....");
for (int cnt=0;cnt<(int) NbOfLines;cnt++ )
{
* * * * StringBuilder textBuffer = new StringBuilder() ;
* * * * int NbOfChars=SendM essage(1050958, EM_GETLINE,cnt, textBuffer);
* * * * CtrlContent+=te xtBuffer.ToStri ng();}

MessageBox.Show ("Content="+Ctr lContent);

The preceding code placed in a button click event work
perfectly....bu t the same code in a TreeView afterSelect event is not
working at all, the content is always empty without any reasons...

if I put a messagebox before the loop, everything work
perfectly.....T his is totally weird is anybody can explain what is
going on???

This non logic behaviour is a ***MAJOR PROBLEM*** in my application I
really need to find a way to fix this..

Thanks!
This could be a timing relating problem or it could be because
SendMessage does partial messaging pumping while waiting or maybe
something entirely different. It's going to be nearly impossible for
us to give you the answer without being able to replicate it
ourselves, but we may be able to offer clues. Have you tried placing
the code in other locations? How did you declare the SendMessage
function?
Jul 19 '08 #2
On Jul 19, 10:01*am, Brian Gideon <briangid...@ya hoo.comwrote:
On Jul 19, 7:29*am, michelqa <miche...@yahoo .cawrote:
This could be a timing relating problem or it could be because
SendMessage does partial messaging pumping while waiting or maybe
something entirely different. *It's going to be nearly impossible for
us to give you the answer without being able to replicate it
ourselves, but we may be able to offer clues. *Have you tried placing
the code in other locations? *How did you declare the SendMessage
function
[DllImport("user 32.dll")]
public static extern IntPtr SendMessage(int hwnd, int msg, IntPtr
wparam, IntPtr lparam);
[DllImport("user 32.dll")]
public static extern int SendMessage(int hWnd, int msg, int wParam,
StringBuilder lParam);
const int EM_GETLINECOUNT = 0x00BA;
const int EM_GETLINE = 0x00C4;

Ok directly in Form1() function (first line of code at the very
begining of the application) it work in a c# new application.

the same thing in my application is not working....both are C#
project.

timing problem?? ...but why it work for a Button click event and not
for an afterSelect treeview event ??

..
this.InterfaceE lementTreeView. AfterSelect += new
System.Windows. Forms.TreeViewE ventHandler(thi s.InterfaceElem entTreeView_Aft erSelect);
..
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
...
private void InterfaceElemen tTreeView_After Select(Object sender,
System.Windows. Forms.TreeViewE ventArgs e)
{
//The code is NOT WORKING properly if placed here
}
private void button1_Click(o bject sender, System.EventArg s e)
{
//The code is working properly if placed here
}
Jul 19 '08 #3
Just to add more informations...

in my application a lot of SendMessage works correctly, the problem
occurs only for the EM_GETLINE send message.

so look like something strange happen when lParam is a string and not
an IntPtr
Jul 19 '08 #4
Im still tinking the way .net manage the conversion of the lparam to
string in my sendmessage is the cause of this.
But WM_GETTEXT is working correctly.... the difference is that
WM_GETTEXT use a parameter for the size of the string.

I will use WM_GETTEXT as a workaround... so thanks to everybody who
try to help.

BUT still want to understand that behaviour...don t hesitate if you
have an explanation. Send an email to mi******@yahoo. ca if you want
to take a look at the problem in my C# project

Thanks again.

Jul 22 '08 #5

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

Similar topics

3
2361
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ---------------------------------------------- //example 1: typedef int t_Array; int main(int argc, char* argv)
3
6741
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is
29
5082
by: Charles Law | last post by:
Further to my issue about user controls, I have a problem with DesignMode. Here is the project hierarchy: MainApp |_ Project1 |_ SubProject (UserControl) SubProject has a default constructor (New) which does the MyBase.New() thing and then InitializeComponent().
10
1209
by: tborn | last post by:
Hi there, Not sure if any one has experienced this before and can tell me what's wrong with this statement: if verified = false then dataObjects.HasError = true This is all on one line and verified is defined as a boolean variable. Irrespective if verified is set to true or false in ALWAYS executes
11
7346
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz 1.7.12 (linux kubuntu). It does work with konqueror. It seems to work with firefox on windows but not with IE (not completly sure though).
5
3110
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view showing a list of jobs from the database. When the main form loses focus and the user clicks the 'Close' button, I kept receiving error 2585 (This action cannot be carried out whilst processing a form or report event). This was tracked down to...
22
9258
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. I'm sure the problem is the way i'm using the sendmessage API, the return string and the lParam return 0....is anybody have a clue? any sendmessage api expert here? public static extern Int32 FindWindow(String lpClassName,String
8
5318
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
0
145
by: michelqa | last post by:
Hi, I use sendMessage to retrieve information from another application. For some obscur reasons, my code work only in a button click event and nowhere else in my application. I mean I get unexpected result depending where the code is placed in my application ?!?!?!?!? Here is my code: ================================
0
9618
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
10101
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
10038
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
9906
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
8933
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...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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 we have to send another system
2
3609
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.