473,406 Members | 2,769 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,406 software developers and data experts.

Problem using SendMessage Win api c#

Hi,

I am trying to find text in a window. I can get the handle to the
window but when I try using SendMessage the return value is very large
number. When I use Spy++ to see the return value it is FFFFFFFF. I
don't think SendMessage is working correctly to find the text. Can
somebody help me out here with the parameters that need to be passed
and if I am passing them correctly.

How do i specify the pointer to string member in the FindText
structure in C#?

My code is as follows:
public long FindTextW()
{
RichEdit.FindText tEx;

sText = "John\0";
IntPtr lstrPtr = Marshal.StringToCoTaskMemAuto(sText);;
//tEx is the FINDTEXT structure
tEx.lpstrText =lstrPtr;
tEx.chrg = tCR;
tEx.chrg.cpMax = -1;
tEx.chrg.cpMin = 0;
IntPtr lPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(tEx));
Marshal.StructureToPtr(tEx, lPtr, true);
lR = RichEdit.SendMessage((IntPtr)m_hWnd,RichEdit.EM_FI NDTEXT,0,lPtr);
return lR;
}

The value I get for lR is 9222812406911074303 which doesn't seem
right!!

Any help will be really appreciated!
Thanks,
jbhan
Nov 15 '05 #1
4 2335
The value I get for lR is 9222812406911074303 which doesn't seem
right!!


Then you've probably declared the return type as long, which is
incorrect. It should be more like

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam,
IntPtr lParam);

Also, I don't thing Windows will marshal the parameters of this
message cross process boundaries, so you can probably only expect it
to work if you send it to a control in your own process.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
Thanks for the info. I changed the return type for SendMessage to IntPtr and I get a return value of -1
I am basically trying to FindText in an open Outlook window (I am able to get the handle to the window) from my windows application.I can even get the total number of text lines in the Outlook window using SendMessage. But the same api fails for FINDTEXT
Do you have an idea what is wrong with my parameters and if there is any other way I can pass them

Really appreciate your help

Thanks
jbha
Nov 15 '05 #3
Do you have an idea what is wrong with my parameters and if there is any other way I can pass them?


There's probably nothing wrong with your parameters. It just doesn't
work to send this message cross process boundaries. You'd have to get
code running inside the Outlook process one way or another to do this.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4
I am running this code in an Outlook addin, so I presume it is running in the same process as Outlook
Even there I get a constant error "Object reference not set to an instance of an object"
What am I missing here?
Any pointers would be really great

Thanks
jbhan.
Nov 15 '05 #5

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

Similar topics

9
by: none | last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs to be modified. The problem I have is this: The SysAdmin uses this shell in place of Explorer, so there is no taskbar. When...
5
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response =...
0
by: jbhan | last post by:
I am trying to find text in a window. I can get the handle to th window but when I try using SendMessage the return value is very larg number. When I use Spy++ to see the return value it is...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
1
by: Frederik Vanderhaegen | last post by:
Hi, I'm trying change the layout of a combobox when f.e. a certain property is set to true. My problem is the following: when I execute the code, the combobox is repainted but there always...
16
by: Abubakar | last post by:
Hi all, My solution consists of 2 projects, 1 is a dll (contains sockets functionality, multithreaded), and the other is a wtl gui project. Both are totally unmanaged. The gui app has a edit...
2
by: Mayur | last post by:
I tried followinf but working fine fo int but how to do it for string using user custome message in c# public static extern int FindWindow(string strClassName,string strWindowName);
2
by: d-42 | last post by:
Hi, I'm pretty sure I've just got a Marshalling problem, but I'm completely stumped. If there is a better newsgroup to post this in, please point me towards it. First I'm trying to use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...
0
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,...

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.