The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
How to send a windows message from C# to C++ (MFC)?
Discuss How to send a windows message from C# to C++ (MFC)? in the C Programming forum on Dev Shed. How to send a windows message from C# to C++ (MFC)? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 20th, 2012, 03:56 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 2
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!
|

December 20th, 2012, 07:14 AM
|
 |
Contributed User
|
|
|
|
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.
|

December 20th, 2012, 10:20 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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.
|

December 21st, 2012, 04:13 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 2
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?
|

December 21st, 2012, 03:21 PM
|
|
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|