C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 20th, 2012, 03:56 AM
CarlosEver CarlosEver is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 CarlosEver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 21 sec
Reputation Power: 0
How to send a windows message from C# to C++ (MFC)?

Hello mates,

I'm trying to send a windowsmessage from an app in C# (Compact Frame) to another one in C++ (MFC), both of them in a PDA.

In the receiver app (MFC) I realize that I receive the message but I can't read the string message, it shows a little square.

This is the code of the Sender (C#)

Code:
OpenNETCF.Win32.Win32Window.SendMessage(hwndVal, typeMsgVal, intValue, stringMessage);


And this is the code of the receiver (C++)

Code:
CString myStr = (CString) lParam;
    AfxMessageBox(myStr);



Thanks a lot in advance!

Reply With Quote
  #2  
Old December 20th, 2012, 07:14 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,838 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 17 h 9 m 51 sec
Reputation Power: 1774
Did you compile your C++ code with UNICODE enabled?

In any event, putting a breakpoint on
Code:
CString myStr = (CString) lParam;
    AfxMessageBox(myStr);  // breakpoint here!

and running the code in the debugger is the thing to do.

When you hit the breakpoint, use the debugger to examine lParam and myStr in detail to see if you can figure out exactly what the object is.

Maybe it's a pointer to a UNICODE string, and you assume it's ASCII.
Maybe it's just a resource handle, or perhaps a pointer to a pointer.

The point is, if you dig deep enough, you should be able to figure it out.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old December 20th, 2012, 10:20 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,128 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 18 h 27 m 41 sec
Reputation Power: 1949
There may also be an issue with the different class types. .NET's String (which I assume that stringMessage is based on) is different from CString. You might need to work out a conversion from String to something that CString will be able to handle upon receipt. I remember encountering that kind of problem when I first tried to work with C++ under .NET, having to convert from string to String and back again in order to work with the GUI, which is why I decided to just learn C# instead. So just exactly what is it that the C# app is sending?

And, of course, the UNICODE vs ASCII issue as well which should be looked into first.

Reply With Quote
  #4  
Old December 21st, 2012, 04:13 AM
CarlosEver CarlosEver is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 CarlosEver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 21 sec
Reputation Power: 0
Thanks for your answers.

The C# have to send a string message for a printer configuration.
The problem is that I can't debug the C++ app in the PDA, I can only debug the C# app.

The C++ code:

Code:
CString myStr = (CString) lParam;     AfxMessageBox(myStr); 


I tried to put the string in C# as:

- String stringMessage= "hello"
- System.String.Format("hello")
- System.String.Format("hello").ToString()


I'm trying to send the string as a Byte[] but i don't know how to convert the Byte[](C#) to a CString of C++

Any ideas?

Reply With Quote
  #5  
Old December 21st, 2012, 03:21 PM
BobS0327 BobS0327 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 118 BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 18 h 48 m 29 sec
Reputation Power: 44

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How to send a windows message from C# to C++ (MFC)?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap