C++ Structure using Windows Messages.

Hi guys,
        Is there any way to send structure using windows Messages.
I know we can use WM_COPYDATA message to send the information to the
other application.But i donot want to use that. Iam creating a user
defined message using RegisterWindowMessage.I want other applications
to use this message in order to read the structure. Iam using
HWND_BROADCAST to send the structure.Is there any way i can do this.

thanks in advance,
Sada

0
10/24/2005 2:13:15 PM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
1186 Views

Similar Articles

[PageSpeed] 6

sada wrote:
> Hi ,
> That was an excellant idea.But one more question ( :) ) .Wouldn't their
> be any other application affected by sending WM_COPYDATA using
> HWND_BROADCAST.

Yes, and your application could be affected by receiving broadcasts from 
other applications.

1. Prefix the message with something very unique, such as a GUID known 
only to your applications.
2. You can use FindWindow and custom winclass names to get the HWND you 
wish to send to.  This avoids broadcasting.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
10/24/2005 4:12:56 PM
Each application under 32-bit Windows has its own address space. This means
that one application cannot read data that is part of another application.
If you need to send a structure, then you really need to use something like
WM_COPYDATA, which copies data from one address space to another.

You could use something else and maybe make the data available in a file
instead, where any application can read it. But I see some potential
problems with that. It may make more sense to associate some id number that
can be verified in combination with WM_COPYDATA.

-- 
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm

"sada" <sadashiv.borkar@gmail.com> wrote in message
news:1130163195.527091.250860@g14g2000cwa.googlegroups.com...
> Hi guys,
>         Is there any way to send structure using windows Messages.
> I know we can use WM_COPYDATA message to send the information to the
> other application.But i donot want to use that. Iam creating a user
> defined message using RegisterWindowMessage.I want other applications
> to use this message in order to read the structure. Iam using
> HWND_BROADCAST to send the structure.Is there any way i can do this.
>
> thanks in advance,
> Sada
>


0
jwood (1292)
10/24/2005 6:35:02 PM
Hi ,
That was an excellant idea.But one more question ( :) ) .Wouldn't their
be any other application affected by sending WM_COPYDATA using
HWND_BROADCAST.

thanks and regards,
Sada

0
10/24/2005 7:27:32 PM
Why not use WM_COPYDATA. There are other ways which involve COM but
this is by far the easiest. Here is the sample:

http://www.codersource.net/mfc_ipc_wm_copydata.aspx

----------------
Ajay Kalra
ajaykalra@yahoo.com

0
ajaykalra (6842)
10/24/2005 7:42:08 PM
Yes, so you should try and find the handle to the window you want rather
than using HWND_BROADCAST. In addition, you should include some code in your
data for verification in case another application used WM_COPYDATA using
HWND_BROADCAST.

-- 
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm

"sada" <sadashiv.borkar@gmail.com> wrote in message
news:1130182052.790337.26930@g14g2000cwa.googlegroups.com...
> Hi ,
> That was an excellant idea.But one more question ( :) ) .Wouldn't their
> be any other application affected by sending WM_COPYDATA using
> HWND_BROADCAST.
>
> thanks and regards,
> Sada
>


0
jwood (1292)
10/24/2005 9:43:33 PM
Hi Mr. Sada,
 WM_COPYDATA will be most effcient way to transfer C++ Structure  between 
two application. there are some more method using which which you achieve 
same 
i.e. allocate memory using global alloc, copy the data into that memory 
location  and pass  the memory address as parameter to another application.. 
(but here can be memory management problem.

Second Choice, as you have already mentioned about RegisterWindowMessage, 
but instead of sending data using it use it as window Finder i.e. See this 
Code Snippet

First Application :-
      int iRegMesg=RegisterWindowMessage("thatsalok");
       PostMessage(HWND_BROADCAST,iRegMesg,GetSafeHwnd(),0);// BraodCast 
it's Hwnd

Second application:- 
   On recv register Message :-
 LRESULT  OnRegMessage(WPARAM wParam,LPARAM lParam)
  {
   //Since wParam Member contain teh window handle So copy it a variable
    m_TargetHWnd=(HWND)wParam;

  //Send it's HWND to first application
    int iRegMesg=RegisterWindowMessage("thatsalok");
    PostMessage(m_TargetHWnd,iRegMesg,GetSafeHwnd(),0);// reply using 
Register message  
   
 
  }

 Same way the First Message Save the handle of Second Window.. and use this 
with WM_COPYDATA message.

#3 Way :- U can also use Named Pipes to send the data :)

 
-- 
Cheers
Alok Gupta
Blogs:http://blogs.wdevs.com/thatsalok


"sada" wrote:

> Hi ,
> That was an excellant idea.But one more question ( :) ) .Wouldn't their
> be any other application affected by sending WM_COPYDATA using
> HWND_BROADCAST.
> 
> thanks and regards,
> Sada
> 
> 
0
10/25/2005 10:41:04 AM
Absolutely.  Read my essay on my MVP Tips site on the use of WM_COPYDATA, and how I got
nuked by some irresponsible program that did a SendMessage(HWND_BROADCAST, WM_COPYDATA...)
and how I had to fix it.  
				joe
On 24 Oct 2005 12:27:32 -0700, "sada" <sadashiv.borkar@gmail.com> wrote:

>Hi ,
>That was an excellant idea.But one more question ( :) ) .Wouldn't their
>be any other application affected by sending WM_COPYDATA using
>HWND_BROADCAST.
>
>thanks and regards,
>Sada
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
10/27/2005 2:03:01 AM
Also, you should give an example of the kind of structure you want to pass.  For example,
you can't pass CString, CArray, etc.; you can only pass structs that contain simple
scalars or which contain other structs which are simple scalars.  But if anything in your
struct involves any kind of pointer, it's all over.  You will have to create some form of
serialized data to send via the WM_COPYDATA.
					joe

On Tue, 25 Oct 2005 03:41:04 -0700, thatsalok <thatsalok@gmail.com_I_DONT_NEED_SPAM>
wrote:

>Hi Mr. Sada,
> WM_COPYDATA will be most effcient way to transfer C++ Structure  between 
>two application. there are some more method using which which you achieve 
>same 
>i.e. allocate memory using global alloc, copy the data into that memory 
>location  and pass  the memory address as parameter to another application.. 
>(but here can be memory management problem.
>
>Second Choice, as you have already mentioned about RegisterWindowMessage, 
>but instead of sending data using it use it as window Finder i.e. See this 
>Code Snippet
>
>First Application :-
>      int iRegMesg=RegisterWindowMessage("thatsalok");
>       PostMessage(HWND_BROADCAST,iRegMesg,GetSafeHwnd(),0);// BraodCast 
>it's Hwnd
>
>Second application:- 
>   On recv register Message :-
> LRESULT  OnRegMessage(WPARAM wParam,LPARAM lParam)
>  {
>   //Since wParam Member contain teh window handle So copy it a variable
>    m_TargetHWnd=(HWND)wParam;
>
>  //Send it's HWND to first application
>    int iRegMesg=RegisterWindowMessage("thatsalok");
>    PostMessage(m_TargetHWnd,iRegMesg,GetSafeHwnd(),0);// reply using 
>Register message  
>   
> 
>  }
>
> Same way the First Message Save the handle of Second Window.. and use this 
>with WM_COPYDATA message.
>
>#3 Way :- U can also use Named Pipes to send the data :)
>
> 
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
10/27/2005 4:29:52 AM
Reply:

Similar Artilces:

Isinteg Warning Message Question
I ran isinteg -pri -test alltests. I came up with 506 warnings. There are basically 4 types of warnings. They are below. Are these something I need to worry about? What should I do? thanks stewart sschwartz@nal.usda.gov ================================== Warning: MsgFolder 165 (Fid=0001-0000000D1864, Mid=0001- 0000000D559D, Inid=0001-000000F33436): PR_READ_RECEIPT_REQUESTED(0029000B) prop in Messages table and MsgFolder table do not match. Warning: MsgFolder 4 (Fid=0001-0000086DC911, Mid=0001- 00000436F972, Inid=0001-000004A583F1): Error JET_errRecordNotFound seeking to INID for this ...

Window Redirection?
A PrintWindow API related sample application in MSDN has this line - The API uses window redirection to paint a snapshot of the window into the hdc. What is window redirection? Is it possible to use this outside PrintWindow API to get a visual image of the window without actually having to show the window? (Note - PrintWindow needs the window displayed for it to work) TIA Priyesh ...

Money and Windows Mobile 5.0 Devices
I've got a new Windows Mobile 5.0 device and have found that the PPC Money client for Money 2005 will not sync to it. From http://www.microsoft.com/money/MoneyForHandHeldDevices.mspx it appears Money 2004-6 will not sync but it doesn't mention anything about Money 2007...but I can't find a Windows Mobile Client for 2007. Is there anyway to get any version of Money to sync to a Windows Mobile 5.0 device? Thanks, Don Not at present, except by using third party software such as SPB Finance/ -- Glyn Simpson, Microsoft MVP - Money http://money.mvps.org See http://money.mvps.or...

Using mouse wheel in VB editor
Just tried using the mouse wheel to scroll within visual basic editor in excel but it wont let me. How can I turn this feature on. I am using Excel 2003. Thanks in advance. This is a known problem with the latest MS mouse drivers. You can either install version 4 of the drivers (current version is 5), or use FreeWheel, and freeware program at http://www.geocities.com/SiliconValley/2060/freewheel.html . -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "fullers" <fullers@discussions.microsoft.com> wrote in message ne...

Send to certain person using specific email account
I send an email to a certain receipient but don't want to use the default email account. Is it possible that when I send to them (plain text) , that it will choose the other account I want to use to send it? Please advise how I set this up. Thanks. I do not believe that this can be achieved automatically through standard use of Outlook as you need to manually specify the name of the account to send from if different than the default. However, it would be possible using the Outlook object model. An Addin would need to be developed that monitored each mail item prior to sending. If the d...

Where is the cache files folder located for windows media player?
Does windows media player have a cache files folder? Where is the cache files folder located for windows media player? Or how do I find the cache files folder for windows media player? Thank You for your Help. Bob Background info: I have a desktop AMD 4400+ 64X2 4GB memory 320GB HD(way bigger than I need) Acer computer (AM3100-U3201A) I purchased new February 2008 running 32-bit MS Vista Home Premium SP2 box. I use MS auto updates. I think it has onboard shared memory for video and sound. My ISP is Comcast 12mbps with Motorola SURFboard SB5101 Cable Modem direct to...

Messages Cut off
A recipient receives forwarded mail messages that are cut off in random locations throughout the email. Outlook 2000 with latest SP. Any ideas? ...

Interface not registered message
when i try to send a e-mail message through outlook, i get the message interface not registered ? and then can't even save message. can anyone tell me why ? ...

Outlook Hangs Reading Messages
I am running Windows XP Pro & Outlook 2003 via POP3 & Symantec AV I had to reinstall everything on my pc and now find when I double click an email outlook hangs for roughly a minute and then it finally opens, I have tried a data compact, reinstalling outlook and creating a new pst then importing but it still happens Does anyone have any ideas? It's driving me mad Thanks Daz Try deleting and recreating the profile as one of your steps in troubleshooting: http://www.howto-outlook.com/Faq/newprofile.htm -- K. Orland Thoughts lead on to purposes; purposes go forth in action; ...

Use exchange from a trusted domain
Hi folks, I have domain a and domain b. Domain a is all set upp with exchange etc. Domain b was bought, and they don't have exchange. I have trust between the domains and file sharing and authentication are ok. What we want to do is, make users on domain b and let them use the exchange (on a seperate storage) on domain a. The users on domain b must logon to domain b, but need to have mailbox on domain a. Domain a are running on win2003 and exchange 2003. Domain are running on win2003 with forest and domain ready for exchange. Any advices? thanks in advance, - Bjarni Hi, Thi...

Outlook rule to move read message from Blackberry
I have Outlook configured with a Blackberry server and want to set up a rule to mange messages marked as read: For example. 1. I'm away from the office, Outlook is closed. 2. I read an email on my Blackberry, which marks the message "read" 3. When I return to the office and open Outlook I want to: a. Apply a rule to my inbox that states: If message is marked as read, move to folder "read messages" b. All unread messages will remain in the inbox. I'm a heavy user of rules but I can't find a way to identify "read" messages. Any thoughts? view360@gm...

Windows Server 2008 R2 04-09-10
Windows Server 2008 R2 and Windows 7 share the same code? how is that possible when Windows 7 has both 32 bit and 64 bit versions and windows server 2008 r2 is only 64 bit Hello Charle, As Microsoft is going to use only 64bit versions for servers they don't built the 32bit version. Sharing the same code doesn't mean that the server OS use exaclty the same files, there are a lot more and different ones. But the basic code is the same. Best regards Meinolf Weber Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights. ...

Using Access 2003 on client to see Sharepoint 2007
Testing a Sharepoint environment and I can easily manipulate and run the database from Access 2007, but when I try to use Access 2003 it wants me to save the database to a location. The Access 2003 has the compatiblity pack, but it seems to not work when I download it. So the question is using Sharepoint 2007 and posting the Access 2007 format to it, can a user go to the sharepoint site and use a 2003 Access database that has the compatibility pack and open without having to download it? -- Message posted via http://www.accessmonster.com Send check for $500.00 to: David A Jenn...

Duplicate Messages
I have just upgraded from Office 2000 to Office XP. Ever since, i have been receiving duplicate email messages. Every time i do a send/receive, about 80% of my emails arrive twice (exactly the same ID, time, date etc.) I have got some rules running but these are necessary. Any ideas anyone. Thanks ...

Forwarded messages are not being sent
One of our users is trying to setup his account to forward all messages to his yahoo account. We setup a rule that says keep a copy in his inbox and forward a copy to his yahoo account. The yahoo copy never gets out and message tracking says it is submitted to the categorizer but never gets any farther. What do we need to do? By default rule-based forwards to external recipients are disabled. To change this, go to Exchange System Manager, Global Settings, Internet Message Formats.. There, you can either enable this for all domains (*), or be specific and create a separate policy f...

Ctrl+D not working on outlook messages
Any idea why? alltimefav wrote: > Any idea why? And what are you expecting to happen? "alltimefav" wrote in message news:a95c52df-a387-4a8f-bf9d-269ff485451f@i29g2000prf.googlegroups.com... > Any idea why? So instead of hitting Ctrl+D to delete an item, what happens when the item is selected and you hit the Del key, or the "X" toolbar button, or right-click on the item and select Delete? Did you really expect a detailed response for such a vague question? You didn't even bother to say what "not working" means, like the item does not get delete...

How Use ShellExecute with a CMemFile
Hello, I need to store files of various types (such as .doc, .xls, .jpg, .pdf, ..wmv, ...) in a database. Upon retrieval of such a file I have the file as data in memory in a CMemFile. I need to then "display" the file in the aproriate application. If I were to write the CMemFile to disk and create an actual file I could then, of course, use ShellExecute() to launch , say Word to display a .doc file. However, I would much prefer to avoid the overhead of writing the data to an actual file and then dealing with having to detect when the User is done and cleaning up the file I had ...

Visual C++ 2005 always rebuilds
I have an MFC DLL project that I recently moved over to Visual Studio 2005. However now the project always rebuilds entirely whenever I start debugging. Even if I have only made a simple change to one file. Any help would be greatly appreciated. Thanks Colin Check the date on your source files to make sure that they are not in the future. AliR. "Colin J Paterson" <nospam@thanks.com> wrote in message news:ObtLxgTbGHA.1196@TK2MSFTNGP03.phx.gbl... > I have an MFC DLL project that I recently moved over to Visual Studio 2005. > However now the project always rebuild...

Can i use conditional formating on a cell when it contains a formula?
I am trying a "conditional formatting" on a cell that contains formula, but it didn't work. "If cell value is equal to 0 then font - white" This doesn't work, stays always. If i use this condition on a cell without formula it works just fine. Thank -- si ----------------------------------------------------------------------- sit's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=262 View this thread: http://www.excelforum.com/showthread.php?threadid=26784 Hi are you sure your formula returns an exact zero?. Could you post the formul...

SUTA state message on Pay Code Integration
I'm having trouble importing pay codes that are based on another code, such as Sick and Vacation. These records get rejected with the error message "pay code 'V' requires a SUTA state". I have a SUTA state in the Emp Maint window and the HOURLY pay code already exists and contains a SUTA state. I tried mapping the SUTA State code in my file and even tried using a Constant value in Destination mapping but these codes will not import. I can go into the Pay Code Maintenance window and add these codes manually with no problem. What am I missing? ...

Using INDIRECT within functions
I learned a bit from JLathman in a previous post but tried to use the same methodology with this formula (also learned from this Group to get the last entered value in a column) without much luck. The original formula was this with 2009 sheet being static: =LOOKUP(2,1/('2009'!H3:H65536<>""),'2009'!H3:H65536) Trying to make it dynamic I tried the following without success: =LOOKUP(INDIRECT("2,1/(" & O1 & "!$H$3:$H$65536<>"")," & O1 & "!$H$3:$H$65536)")) Did I miss something or are...

Word 2003: Will it work on Windows 7 Pro
The ads say there is virtual XP on Windows 7 that can run programs like Word 2003. In your experience is this true? On any Windows 7 machine? Does 64 versus 32 bit processor matter for either Word/Office 2003 or Office 2007? thanks. You don't need Virtual XP to run Office 2003 on Windows 7. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "removing all headers and footers" <removingallheadersandfooters@discussions.microsoft.com> wrote in message news:95298031-44F6-4E74-A608-C76987DFAB46@microsoft....

How to use count for calls per hour
I am trying to create a pivot table and chart that will show me the # of calls per hour by day for a range of dates Aug 1 - Sept 19. My data looks like this where each line is the date and time of the call: How do I get a count of the # of the calls per hour by day? 8/1/08 12:48 AM 8/1/08 1:53 AM 8/1/08 2:36 AM 8/1/08 3:24 AM 8/1/08 3:37 AM 8/1/08 4:04 AM 8/1/08 4:44 AM 8/1/08 4:55 AM 8/1/08 4:58 AM 8/1/08 7:02 AM 8/1/08 7:28 AM 8/1/08 7:43 AM 8/1/08 7:47 AM 8/1/08 7:56 AM 8/1/08 7:58 AM 8/1/08 8:13 AM 8/1/08 8:33 AM 8/1/08 9:07 AM 8/1/08 10:28 AM 8/1/08 10:38 AM 8/1/08 10:44 AM 8/1/08 ...

How export all mailbox-enabled users from the GAL using Outlook?
Hello, We have a user which, for administrative reasons, needs to export all mailbox-enabled users in the GAL now and then. They just need all the names. Is there a straightforward way for them to do that? We don't want to give them any special permissions and want to avoid server scripting. Ideally, they should be able to export it to a CSV file or any text file. Thanks, - Alan. Alan wrote: > We have a user which, for administrative reasons, needs to export all > mailbox-enabled users in the GAL now and then. They just need all the > names. Is there a straightforward way fo...

Entourage (allegedly) cannot see message body sent by OWA
We have a external company receiving emails from us and claim they cannot see the message body when the email is sent from OWA. We are on 2003 SP2 btw. The external party claims that the following patch for OWA fixes the problem http://www.microsoft.com/downloads/details.aspx?familyid=5BC06E8A-08EB-4976-BC68-A03EBE3A2552&displaylang=en I am sceptical! Any thoughts Ignore!! I just saw another thread wit hthe details for this one. Thread is "OWA message text disappears" "Peter T" wrote: > We have a external company receiving emails from us and claim they cannot...