473,396 Members | 1,853 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,396 software developers and data experts.

Processing custom windows message

I have created a custom windows message and using SendNotifyMessage
(user32.dll) the message is sent (broadcasted).

I send the message as follows:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendNotifyMessage(IntPtr hwnd, IntPtr
wMsg,
IntPtr wParam,
IntPtr lParam);

SendNotifyMessage((IntPtr)0xffff, RegisterWindowMessage("somestring"),
Marshal.StringToHGlobalAuto("a message"),
Marshal.StringToHGlobalAuto("another message"));

I am receiving the message in another c# app as follows:

protected override void
WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg == RegisterWindowMessage("somestring"))
{

string s = Marshal.PtrToStringAuto(m.WParam);
}

else
{
base.WndProc(ref m);
}
}
The message is received in WndProc without any problems, however the
lparam and wparam properties (when marshalled) have empty strings.

It seems that the pointer created in the sendmessage call points to a
section in memory that when in the WndProc call points to nothing at
all.

When I inspect the memory location in the app that sends the message,
the messages are in fact there.

Does anyone have any advice or suggestions as to what might be wrong?

Thanks in advance.

Ryan Fransen
Nov 17 '05 #1
2 9010
Ryan,
SendNotifyMessage((IntPtr)0xffff, RegisterWindowMessage("somestring"),
Marshal.StringToHGlobalAuto("a message"),
Marshal.StringToHGlobalAuto("another message"));
You're leaking memory here by not freeing the memory you allocate.

Does anyone have any advice or suggestions as to what might be wrong?


The pointers are only valid in the process that sends the message. If
you want to transfer strings to other applications you should look at
using WM_COPYDATA or shared memory.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
Mattias Sjögren <ma********************@mvps.org> wrote in message news:<u$*************@TK2MSFTNGP15.phx.gbl>...
Ryan,
SendNotifyMessage((IntPtr)0xffff, RegisterWindowMessage("somestring"),
Marshal.StringToHGlobalAuto("a message"),
Marshal.StringToHGlobalAuto("another message"));


You're leaking memory here by not freeing the memory you allocate.

Does anyone have any advice or suggestions as to what might be wrong?


The pointers are only valid in the process that sends the message. If
you want to transfer strings to other applications you should look at
using WM_COPYDATA or shared memory.

Mattias

Once again, Mattias saves the day...

Thanks again for your help.

Ryan
Nov 17 '05 #3

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

Similar topics

3
by: | last post by:
I have created a web setup project for my ASP.NET application that works fine. Also, I have followed the instructions for using a custom action to launch a web page after the installation is...
7
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*"...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
4
by: acantatore | last post by:
Hello! I'm looking for patterns, best practices, examples - reference material - that apply to Batch Processing, that is: Basic job control (start and stop) Job partitioning Parallel...
2
by: rdemyan via AccessMonster.com | last post by:
My application has a lot of complicated SQL statements, calculations, processing that takes time. I've created a custom form to act like a messagebox. It has 10 small rectangles on it that change...
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
6
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, We have a requirement where we have to develop a custom Login Page which will accept user's NT credentials ( Username , password, domain name). This then needs to be passed to a website...
1
by: Steveaux | last post by:
Hi, I'm new to ASP.Net, so this may be something simple that I forgot. I have a form where a person can create a login. I'm doing the processing on this myself. The form has a plethora of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
0
Oralloy
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,...
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
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.