473,246 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

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=SendMessage(1050958,EM_GETLINECOUNT,IntP tr.Zero,IntPtr.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=SendMessage(1050958,EM_GETLINE,cnt,textB uffer);
CtrlContent+=textBuffer.ToString();
}
MessageBox.Show("Content="+CtrlContent);
The preceding code placed in a button click event work
perfectly....but 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.....This 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 1657
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=SendMessage(1050958,EM_GETLINECOUNT,IntP tr.Zero,IntPtr.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=SendMessage(1050958,EM_GETLINE,cnt,textB uffer);
* * * * CtrlContent+=textBuffer.ToString();}

MessageBox.Show("Content="+CtrlContent);

The preceding code placed in a button click event work
perfectly....but 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.....This 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...@yahoo.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("user32.dll")]
public static extern IntPtr SendMessage(int hwnd, int msg, IntPtr
wparam, IntPtr lparam);
[DllImport("user32.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.InterfaceElementTreeView.AfterSelect += new
System.Windows.Forms.TreeViewEventHandler(this.Int erfaceElementTreeView_AfterSelect);
..
this.button1.Click += new System.EventHandler(this.button1_Click);
...
private void InterfaceElementTreeView_AfterSelect(Object sender,
System.Windows.Forms.TreeViewEventArgs e)
{
//The code is NOT WORKING properly if placed here
}
private void button1_Click(object sender, System.EventArgs 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...dont 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
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. ...
3
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...
29
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...
10
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...
11
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...
5
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...
22
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. ...
8
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....
0
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...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.