passing COleDateTime with lparam in postmessage

I am trying to pass a time value to another application. 

Message that is sent:

	struct sendMsg{
		COleDateTime curTime;
		CString namedView;
	} curMsg;
	curMsg.curTime = GetTheShow().GetShowTime();		
	::PostMessage(HWND_BROADCAST, 
                      wm_Message, 	
                      (WPARAM) m_hWnd,
                      (LONG) &curMsg); 

Message received:
struct recMsg{
		COleDateTime curTime;
		CString namedView;
	} &in =*(recMsg*) lParam;
currentTime = in.curTime //currentTime is COleDateTime

I am obviously casting incorrectly. I could put value in a string if
that is easier Any ideas are appreciated. -Kathleen
0
kathleen1 (2)
6/15/2004 5:47:54 AM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
589 Views

Similar Articles

[PageSpeed] 7

You are passing the address of the structure as lParam, so you need to cast
lParam as a pointer when receiving:

} *in =(recMsg*) lParam;
currentTime = in->curTime;

Couple of additional points:
(i) you probably don't want to use PostMessage(), and it will certainly
fail/crash/etc if the source structure is temporary (eg created locally in
the function just before PostMessage). PostMessage() puts the message up
there and then continues. Use SendMessage() instead, which waits for the
receiving end to finish.
(ii) I hope you're not really declaring the struct in 2 different places?
Don't *ever* do that... it will hurt you real bad. Define the structure in a
header file that is #included in both sources.

..h

struct BunnyRabbit {
    int ears, tail;
};

A.cpp

BunnyRabbit fluffy;
fluffy.ears = 2;
fluffy.tail = 1;
SendMessage(WM_XXX, 0, (LPARAM)&fluffy);

B.cpp

const BunnyRabbit *pfluffy = (const BunnyRabbit *)lParam;
do something with pfluffy->ears;
[const assuming you're not modifying fluffy here]


"Kathleen Liston" <kathleen@listons.net> wrote in message
news:18f667b1.0406142147.187c752b@posting.google.com...
> I am trying to pass a time value to another application.
>
> Message that is sent:
>
> struct sendMsg{
> COleDateTime curTime;
> CString namedView;
> } curMsg;
> curMsg.curTime = GetTheShow().GetShowTime();
> ::PostMessage(HWND_BROADCAST,
>                       wm_Message,
>                       (WPARAM) m_hWnd,
>                       (LONG) &curMsg);
>
> Message received:
> struct recMsg{
> COleDateTime curTime;
> CString namedView;
> } &in =*(recMsg*) lParam;
> currentTime = in.curTime //currentTime is COleDateTime
>
> I am obviously casting incorrectly. I could put value in a string if
> that is easier Any ideas are appreciated. -Kathleen


0
GuitarBill
6/15/2004 6:16:35 AM
Kathleen Liston wrote:

> I am trying to pass a time value to another application. 
> 
> Message that is sent:
> 
> 	struct sendMsg{
> 		COleDateTime curTime;
> 		CString namedView;
> 	} curMsg;
> 	curMsg.curTime = GetTheShow().GetShowTime();		
> 	::PostMessage(HWND_BROADCAST, 
>                       wm_Message, 	
>                       (WPARAM) m_hWnd,
>                       (LONG) &curMsg); 
> 
> Message received:
> struct recMsg{
> 		COleDateTime curTime;
> 		CString namedView;
> 	} &in =*(recMsg*) lParam;
> currentTime = in.curTime //currentTime is COleDateTime
> 
> I am obviously casting incorrectly. I could put value in a string if
> that is easier Any ideas are appreciated. -Kathleen

It is useless to pass an address to another application.  Each 
application has a private address space and an address from another app 
is meaningless.  You can, however, pass a buffer using the WM_COPYDATA 
message between applications.  Again, what you pass should not contain 
any addresses.  So first you will have to convert to text because a 
CString object contains a pointer.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
6/15/2004 12:54:17 PM
oops yes I didnt see the "to another application" part...
What I said stands for internal messaging, but it won't work across process
(see other reply)


"GuitarBill" <GuitarBill_at_cox_dot_net> wrote in message
news:ucmUiAqUEHA.760@TK2MSFTNGP12.phx.gbl...
> You are passing the address of the structure as lParam, so you need to
cast
> lParam as a pointer when receiving:
>
> } *in =(recMsg*) lParam;
> currentTime = in->curTime;
>
> Couple of additional points:
> (i) you probably don't want to use PostMessage(), and it will certainly
> fail/crash/etc if the source structure is temporary (eg created locally in
> the function just before PostMessage). PostMessage() puts the message up
> there and then continues. Use SendMessage() instead, which waits for the
> receiving end to finish.
> (ii) I hope you're not really declaring the struct in 2 different places?
> Don't *ever* do that... it will hurt you real bad. Define the structure in
a
> header file that is #included in both sources.
>
> .h
>
> struct BunnyRabbit {
>     int ears, tail;
> };
>
> A.cpp
>
> BunnyRabbit fluffy;
> fluffy.ears = 2;
> fluffy.tail = 1;
> SendMessage(WM_XXX, 0, (LPARAM)&fluffy);
>
> B.cpp
>
> const BunnyRabbit *pfluffy = (const BunnyRabbit *)lParam;
> do something with pfluffy->ears;
> [const assuming you're not modifying fluffy here]
>
>
> "Kathleen Liston" <kathleen@listons.net> wrote in message
> news:18f667b1.0406142147.187c752b@posting.google.com...
> > I am trying to pass a time value to another application.
> >
> > Message that is sent:
> >
> > struct sendMsg{
> > COleDateTime curTime;
> > CString namedView;
> > } curMsg;
> > curMsg.curTime = GetTheShow().GetShowTime();
> > ::PostMessage(HWND_BROADCAST,
> >                       wm_Message,
> >                       (WPARAM) m_hWnd,
> >                       (LONG) &curMsg);
> >
> > Message received:
> > struct recMsg{
> > COleDateTime curTime;
> > CString namedView;
> > } &in =*(recMsg*) lParam;
> > currentTime = in.curTime //currentTime is COleDateTime
> >
> > I am obviously casting incorrectly. I could put value in a string if
> > that is easier Any ideas are appreciated. -Kathleen
>
>


0
GuitarBill
6/15/2004 6:42:40 PM
Thanks so much. I did have a struct in the header file but was trying
out other stuff. This is to support inter-app communication of two
instances of the same app. However, I am still get a 0 value for the
COleDateTime on the receiving end. Any ideas?

Much appreciated. -Kathleen

struct CMessageDateView  
 {
	 COleDateTime time;
	 char      *viewString;
 } ;

in .cpp file
LRESULT CMainFrame::OnMessageDateChanged(WPARAM wParam, LPARAM lParam)
{

// If message is posted from this instance do nothing
    if ( wParam == (WPARAM) m_hWnd )
        return 0;
	
	
	
	const CMessageDateView *recMsg = (const CMessageDateView *)lParam;

	CString str;
	str.Format("%s", FormatDate((COleDateTime)recMsg->time,STANDARD_TIME));
	AfxMessageBox(str);
	return (LRESULT) 0;
}

void CMainFrame::OnProjectConnect() 
{
	
	CMessageDateView curMessage;
	
	curMessage.time = GetTheShow().GetShowTime();
	CString str;
	str.Format("sending %s",FormatDate(curMessage.time,STANDARD_TIME));
	AfxMessageBox(str);

	

	::SendMessage(HWND_BROADCAST, 
                      wm_Message, 	
                      (WPARAM) m_hWnd,
                      (LPARAM) &curMessage); 
	
}
0
kathleen1 (2)
6/15/2004 7:17:17 PM
Kathleen Liston wrote:
> Thanks so much. I did have a struct in the header file but was trying
> out other stuff. This is to support inter-app communication of two
> instances of the same app. However, I am still get a 0 value for the
> COleDateTime on the receiving end. Any ideas?
> 
> Much appreciated. -Kathleen
> 
> struct CMessageDateView  
>  {
> 	 COleDateTime time;
> 	 char      *viewString;
>  } ;
> 
> void CMainFrame::OnProjectConnect() 
> {
> 	
> 	CMessageDateView curMessage;
> 	
> 	curMessage.time = GetTheShow().GetShowTime();
> 	CString str;
> 	str.Format("sending %s",FormatDate(curMessage.time,STANDARD_TIME));
> 	AfxMessageBox(str);
> 
> 	
> 
> 	::SendMessage(HWND_BROADCAST, 
>                       wm_Message, 	
>                       (WPARAM) m_hWnd,
>                       (LPARAM) &curMessage); 
> 	
> }


Are you using the WM_COPYDATA message, as suggested?  If not, nothing 
will work.  If so, you didn't absorb the documentation about this 
message.  The lParam parameter you pass must be a pointer to a 
COPYDATASTRUCT when using this message.  Within the struct you place a 
pointer to your data and its length.

That should get you going, but then you really should make your 
interprocess communication safer.  There is no need to broadcast the 
message if the destination is another instance of your own app, and it 
would also be smart to prepend the message with some unique prefix data 
known only to your app so your receiving app can make sure it has 
received what it is expecting.  After all, you never know when some 
other loose-cannon app might be broadcasting WM_COPYDATA too :(

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
6/15/2004 11:55:37 PM
Reply:

Similar Artilces:

Is It Possible To Pass Parameters to A Pass Through Query
My assumption is that's it's not. At work I use ODBC to connect to our oracle database with Access 2003. There are cases where using a pass through query runs much much faster and I then use it in a make table query to make a local table. In access you can use brackets [] to have it ask for input. May I assume there is no way to do anything like that in a pass through query? Create a PassThrough query and use code to assign the SQL to this query filtering it with a parameter, and then run it e.g Dim MyVariable As Integer MyVariable = InputBox("Please select a Number&quo...

Pass multiple selected values from list box to table
How do I pass multiple selected values from a list box to a table? I've found code to use the values as criteria in a query but would now like to store the values in a table (at least temporarily) thanks in advance. jack Pass selected values from a list box to a table? I don't really think you want to do this. Can you describe more about what you are trying to accomplish? You just store raw data in a table. You don't store manipulated data in a table. Maybe you need a query to do what you want to do... -- Ryan--- If this information was helpful, please indi...

How to pass an object from C++
Hello! We have a C# asp.net web application that is using a COM dll We use the tlbimp to be able to use the COM dll from C# asp.net web application The method InitRules shown below is located in the COM dll. It can be seen below the text Original. Method InitRules below is called from C# but we want to pass an object of type Handle_DS in addition to all the other parameters. You can see the modified InitRules below marked Modified Note the object of type Handle_DS is a C++ object that is created from C# asp.net application and pass into the InitRules I have also copied the whole idl fil...

100% Passing Guaranteed in All I.T. Exams/Certifications at 1st Attempt Hi Friends, To pass all types of I.T Exams/Certifications with mind blowing results in 1st attempt just visit http://www.itreal
100% Passing Guaranteed in All I.T. Exams/Certifications at 1st Attempt Hi Friends, To pass all types of I.T Exams/Certifications with mind blowing results in 1st attempt just visit http://www.itrealexams.com/ and get real time Q&As, Brain Dumps, Real Exams, Study material, E-Books, Video Exams and Labs for your all type of I.T Certification Exams. ...

Passing data between forms
Hi I am working on a project someone else started, and he has this code: If STR_FormName = "FMS_ToDo" Then Page47.SetFocus He obviously expects the name of the last form to be here, but it is not. In fact, when I put Option Explicit at the top - this field was undefined. How is this supposed to work? Stapes ...

Passing arguments to procedures
There is something fundamental that I have failed to grasp about passing arguments to procedures. I have a form featuring a set of unbound controls displaying dates and the corresponding days of the week. (For some reason, the long-date format, on my computer, does not include the latter, as the documentation suggests it might, so it has to be separately calculated and displayed.) A default date is displayed in each control, on Form_Open. This can then be manually adjusted by a pair of ‘up’ and ‘down’ buttons associated with each day/date control pair. In the case of the control ‘St...

IT CertificationzzzZ.....100% GUARANTEED PASS.......!!!@!!!
IT CertificationzzzZ.....100% GUARANTEED PASS.......!!!@!!! Hi guys, If you are serious about your professional career and pass IT Certification exam in first attempt then Visit http://www.FreeExamKing.com and get latest Questions And Answers Dumps for Microsoft, Oracle, Cisco, CompTIA and many more, i have used and found it very helpful. ...

Pass Parameter to stored procedure in pass thru query
How do I pass a parameter to a stored procedure in a pass thru query? I'd like to enter the parameter in a control on a form and then run the pass thru query and pass the parameter to it. I've tried this, but haven't been successful. Any ideas? Thanks. On Sun, 8 Jul 2007 18:04:26 -0500, "SAC" <sac@somewhere.com> wrote: >How do I pass a parameter to a stored procedure in a pass thru query? > >I'd like to enter the parameter in a control on a form and then run the pass >thru query and pass the parameter to it. > >I've tried this, b...

You will pass all the exams at 1st attempt No more headaches and worry about spending the time and money to attempt another exam again. You will pass all of your exams, every time www.FreeExamKing.com
You will pass all the exams at 1st attempt No more headaches and worry about spending the time and money to attempt another exam again. You will pass all of your exams, every time www.FreeExamKing.com ...

OnInitDialog and passing argument
Hello, I want to use a dialog for three different purpose so every time dialog should come up with a different situation. How can I pass argunment(s) to the OnInitDialog window message of the dialog ? Is it possible? Thanks Smith "JSmith" <jsmithmitra@yahoo.com> wrote in message news:u4ajmu$nEHA.3900@TK2MSFTNGP10.phx.gbl... > Hello, > > I want to use a dialog for three different purpose so every time dialog > should come up with a different situation. How can I pass argunment(s) to > the OnInitDialog window message of the dialog ? > Is it possible? The...

How to pass a parameter to a userform
Hi, I need to both open a useform and pass a parameter to it. How do I do this? I'd like to do the following but the Show method doesn't take this kind of parameter. Userform1.Show(param) Cheers Gromit -- Gromit ------------------------------------------------------------------------ Gromit's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=928 View this thread: http://www.excelforum.com/showthread.php?threadid=320229 Create a public variable in the userform, say called myVar, and then Load Userform1 Userform1.myVar = "SomeValue" ...

Passing the id to a function
Hi, I have a CStatic instance as follows: CStatic label1; label1.Create("", WS_CHILD | WS_VISIBLE| SS_BITMAP | SS_NOTIFY, CRect(100+i*(15+32), 100, 60, 60), this, static_id); And I have a corresponding ON_STN_CLICKED(static_id,ThisFunctionClicked); But I am not able to do this for dynamic values for the static_id. For example if I have two CStatic instances, each with a different static_id. But I want to call the same function ThisFunctionClicked for both. But the ThisFunctionClicked needs to know which static_id was invoked in order to make decisions. Can I pa...

by passing SMTP
Hello, On my e-mail system here we use an external company called " postini " which filters our spam. We keep getting spam. My partner said its because it is comming in VIA smtp or other ways by passing postini. Is there a way to accept e-mail that comes only from the Postini IP Address? Please let me know ASAP. Thanks On your firewall, modify the rules to only allow SMTP connections from Postini. You can work with Postini to obtain a list of the IP's they send from. When using Postini, it's also a common practice to remove all MX records except those entries for...

Pass/Name not recognized
When I try to get my e-mail through outlook express, I enter my name an my password and both are correct because they work online but i outlook it keeps asking me for my Pass/Name. I currently have sb yahoo dsl. Please respond if you know how to fix this ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com ...

Pass variables to Worksheet_SelectionChange
I have the following code which works well as it stands. My problem is that I need to vary the range depending on conditions set in other code. Private Sub Worksheet_SelectionChange(ByVal Target As Range) '----- ENABLE TICKS IN RELEVANT BOXES ----- Application.EnableEvents = False On Error GoTo sub_exit If Not Intersect(Target, Worksheets("Room").Range("P11:T39")) Is Nothing Then With Target If .Value = Chr(252) Then .Value = "" Else .Value = Chr(252) .Font.Nam...

Windows XP install passes the 'press any key...' screen
Hello, I'm trying to re-install windows xp on my machine. I am able to get it to boot from the cd, but when I get to the screen that says 'Press any key...' I press keys on the keyboard but it doesn't recognize that i'm pressing anything and starts windows normally. Any work arounds or solutions? Thanks! Katy -- klau962` undisclosed wrote: > Hello, I'm trying to re-install Windows XP on my machine. I am able to > get it to boot from the cd, but when I get to the screen that says > 'Press any key...', I press keys on the keyboard...

Network Diagram
I'm taking a PM class and our instructor had us manually create a network diagram so that we could learn how the forward pass and backward pass are calculated. He also said that the network diagram in project can be configured to show the calculations as well. For example... 0 10 Days Duration 10 instead of dates. I have figured out how to reflect this in diagram box but cannot get it to add the ten days to the duration on the following box. I created a custom number field with a formula to get it to show what is in the example based on my tasks. Any one know how to g...

passing arrays to VB via EXCEL4 API #3
Jim - Nothing personal - thanks for the response. I guess I'll have to kee searching for an Excel archeologist. Say... maybe this knowledge o antiquities is a marketable skill! Hmm... Thanks again, - Ro -- cell divisio ----------------------------------------------------------------------- cell division's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1610 View this thread: http://www.excelforum.com/showthread.php?threadid=27553 ...

Passing a variable to XSL.
Hello, Can someone explain the easiest way to pass an external value to an XSL file? If I have a variable within my ASP file called "ClickArea", can I send the value to my XSL file? I believe I need to use Addparameter somehow, but I have no joy. If someone could post a super quick very basic example of how Addparameter works (VBScript ASP), I can take it from there! :) The Microsoft example seems to generate code errors. Reegards, Gary. Gary Whittle wrote: > Can someone explain the easiest way to pass an external value to an XSL > file? > If I have a variable ...

Passing field to a report
It doesn't help me on how to pass the accountnumber from CRM to a parameter in the report. This should be possible or ? Perhaps this article on MSDN will help you: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk3_0/htm/v3d0usingparameters.asp "Jack" wrote: > Hi ! > > I have made a report and imported it into CRM. It is not a report taking > data from CRM but from an ERP system. > > The thing is I need to pass accountnumber to the report so that the report > shows data from the ERP system for only this account. > > Right now...

Splashscreen by-pass
I installed Excel 2003 on my new computer - I cannot remember how to by pass the 'splash screen' when opening the program. I believe an "-e" is needed somewhere - I cannot remember where. MY OS in Win XP Home SP2 TIA Bill I had to put -turbo after the last " on my Netscape shortcut. Like this "C:\Program Files\Netscape\Netscape Browser\netscape.exe" -turbo Hey it's worth a try...nothing to loose Bobby On Sun, 3 Jul 2005 19:52:18 -0400, "Bill" <smile@here.com> wrote: >I installed Excel 2003 on m...

Can't get length of a variant array passed to a subroutine
I have a string array, declared by: Dim HRColHdrs(3) As Variant I explicitly define the strings, then pass them to a function, as "ColHdrs" shown below. Private Sub HdrChk(ByVal ShtName As String, ByRef ColHdrs As Variant) Dim i, n As Long Debug.Print (Len(ColHdrs)) End Sub Within this function, I would like to determine how many elements are in this array that was passed. However, when I use the len() function, I get Type mismatch error. Things I have tried: -Declaring "HRColHdrs" as an array of type String in the main function (...

Crossing out a day once it has passed on the calendar
How can i cross out a day on the calender after that day is over with. Thanks "john" <jnutella@hotmail.com> wrote in message news:Rm4Ah.14957$4Q2.13975@read1.cgocable.net... > How can i cross out a day on the calender after that day is over with. > > Thanks > > > You could take a permanent marker. After a few days, you would have to buy a new monitor. Really, Outlook highlights the current day. Everything to the left is "over." "Chuck Davis" <newsgroup at anthemwebs dot com> wrote in message news:%23p%23qOhuTHHA.192@TK2...

You will pass all the exams at 1st attempt No more headaches and worry about spending the time and money to attempt another exam again. You will pass all of your exams, every time www.FreeExamKing.com
You will pass all the exams at 1st attempt No more headaches and worry about spending the time and money to attempt another exam again. You will pass all of your exams, every time www.FreeExamKing.com ...

For Each loop doesn't work on First Pass, only on Second Pass
I have a button on my excel with the following code. I have to click on it twice, each time, for it to delete rows that contains "!No_PRorFB_cdt" in column B. Is there something I am doing wrong here? Private Sub cmdBuildKML_Click() Dim siteDataws As Worksheet, DataDLws As Worksheet Dim siteDataws_lastRow As Long, DataDLws_lastRow As Long, i As Integer Dim c As Range, rngAll As Range Application.DisplayAlerts = False Set siteDataws = Worksheets("GoogleEarth_SiteData") Set DataDLws = Worksheets("DATA DOWNLOAD") siteDataws_lastRow = siteDataw...