Hi,
I'm pretty sure I've just got a Marshalling problem, but I'm
completely stumped. If there is a better newsgroup to post this in,
please point me towards it.
First I'm trying to use SendMessage() with WM_COPYDATA to send a
string data between two instances of a program. As part of the
debugging I've written two methods one where a given instance will
obtain its own hWnd and send itself the message, one where it accepts
obtains the hWnd of the other instance and sends it to the other one.
Both methods work fine when compiled as x86. And the send-to-itself
works on x64, but the send-to-another-instance breaks... the
WM_COPYDATA message is sent, and received, but I'm unable to read back
the string data.
I *think* its a marshalling problem related to changes with x64. But
I'm not sure.
Here are the relevant bits:
// The COPYDATA structure used for the WM_COPYDATA message:
[StructLayout(La youtKind.Sequen tial)]
public struct COPYDATASTRUCT
{
[MarshalAs(Unman agedType.U4)]
public int dwData; // not used
[MarshalAs(Unman agedType.U4)]
public int cbData; // holds length of string
[MarshalAs(Unman agedType.LPStr)]
public string lpData; //holds string
}
//DLL Import of SendMessage
[DllImport("user 32.dll", CharSet=CharSet .Ansi)]
private static extern IntPtr SendMessage(Int Ptr hWnd,
[MarshalAs(Unman agedType.U4)] int Msg,
IntPtr wParam, ref COPYDATASTRUCT lParam);
//The function that sends the message:
public static IntPtr SendCopyDataMes sage(IntPtr toHandle)
{
int messageid = 1234; // random message id
stringdata = "Testing\0" ; // send the string "Testing"
// Create/populate the copydata structure.
COPYDATASTRUCT dataStruct = new COPYDATASTRUCT( );
dataStruct.dwDa ta = 0; //not used
dataStruct.cbDa ta = stringdata.Leng th;
dataStruct.lpDa ta = stringdata;
// Make the call
IntPtr result = SendMessage(toH andle, WM_COPYDATA,
messageid, ref dataStruct);
return result;
}
The WndProc that receives the messages is an override of Form.WndProc:
// Process Custom Messages!
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_COPYDATA)
{
// unpack the data
string stringdata = ProcessWM_COPYD ATA(m);
// show what it was
if (stringdata != null)
{
MessageBox.Show (stringdata);
}
}
base.WndProc(re f m);
}
The function it calls to unpack the COPYDATA structure is as follows:
public static string
ProcessWM_COPYD ATA(System.Wind ows.Forms.Messa ge m)
{
if (m.WParam.ToInt 32() == 1234)
{
COPYDATASTRUCT datastruct =
(COPYDATASTRUCT )Marshal.PtrToS tructure(
m.LParam, typeof(COPYDATA STRUCT));
return datastruct.lpDa ta;
}
return null;
}
}
As I said: It works when targeted at x86. In x64 it also works when I
fire the send message at the same instance. (e.g. I have a button on
the form that calls the SendCopyData(.. .) with its own window handle.
The only time it doesn't work is when I have 2nd instance running and
it calls SendCopyData(.. .) with the hWnd of the OTHER instance. In
that case the message is received, and the MessageBox is displayed,
but instead of saying testing its either blank or contains garbage
data.
I'd be grateful if someone can point out where I've screwed it up. As
I said, I think its in marshalling/unmarshalling the lpData string,
but I'm at a loss to fix it. I've tried doing it a number of ways,
including setting lpData in COPYDATASTRUCTU RE to an IntPtr, and then
manually calling Marshal.StringT oHGlobal(string data); and then when
unpacking it, calling Marshal.PtrToSt ring(lpData), but I end up with
the same behaviour... breaking in x64.
-best regards,
Dave 1 2551
>
I'm pretty sure I've just got a Marshalling problem, but I'm
completely stumped. If there is a better newsgroup to post this in,
please point me towards it.
Aw crap. I didn't even post to the newsgroup I intended. Sorry about
that.
-Dave This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lu |
last post by:
Hi,
I have a redhat 9 linux machine running apache 2.0.47, mysql 4.0.15,
and php 4.3.4. I have been puzzled by this mail() problem for quite a
while, could someone please give me some hint on this?
I configured sendmail with a relay so that all outgoing mails go
through our organization's exchange mail server:
DSexchange.domain.com. The php.ini file specified the path to
sendmail: "sendmail_path= /usr/sbin/sendmail -t -i".
|
by: geod |
last post by:
Here's the code in question. Even as the only div in a page, mozilla e
al will render this as 100%. I tried removing the background image
removing padding, doing ANYTHING -- even hard-coding the height in th
HTML page itself. Nothing works. Help!
#right {
position : absolute;
font-family : Verdana, Arial, Helvetica, sans-serif;
font-size : 11px;
line-height : 16px;
background-color : #fffaec;
|
by: Stephen |
last post by:
I was wondering if someone could please help me with an array I'd like to
create in an asp.net page. I have to design an array which stores the values
of addresses manually entered into textboxes (txtAdd,txtCity&txtPostcode).
The array must hold the values of these three textboxes. I would like the
array to also display these address values in an asp:Lable within a
asp:TableCell inside a asp:Table.
I want all this to happen on the...
|
by: Franck Diastein |
last post by:
Hi, when I call ExportData I have this error:
Invalid attempt to Read when reader is closed.
Telling me that there's a problem with this line:
while(_dataR.Read()){
Code:
*************************************************
public void Export2CSV(){
|
by: Michael Chong |
last post by:
I am not very good in C++ problem and this is my codes below. I do not know
whether I got handshaking involve in my code. Could you guys let me know?
HANDLE OpenComm(char *lpszPort, int nBaud, char *nParity, int nData, int
nStop)
{
HANDLE hCom;
LPDCB lpDcb;
| |
by: kumarabhijit |
last post by:
Hi,
Can anyone help me about how to write Marshalling code for Function
pointer in cpp?
Thanks
Abhijit
|
by: Horny LaBelle |
last post by:
The following style sheet for creating drop caps works fine in Safari,
Opera, Omniweb and Explorer, the drop caps extend over 3 lines. Only in
Firefox it doesn't look as it should, they extend over nearly 4 lines
(under Mac OS X). With Firefox under Windows, they extend over 3 lines
but are shifted too high.
Any idea/solution?
Thanks
|
by: Vasu |
last post by:
Hi! Can anybody there help me in analysis of the following code, which
is a structure of customer's details, asks user to fill in the no. of
customers and then their details. When I put in no. of customer as 2
and start filling in users details, in the detail of second customer
till the name of State is OK as soon as I fill in the detail of State
and press enter, it shows the field of PIN code but then suddenly it
says something like...
|
by: Shriphani |
last post by:
Hi,
I was trying to solve the sumtrian problem in the SPOJ problem set
( https://www.spoj.pl/problems/SUMTRIAN/ ) and this is the solution I
submitted: http://pastebin.ca/1035867
The result was, "Your solution from 2008-06-01 15:13:06 to problem
SUMTRIAN, written in Python,
has exceeded the allowed time limit."
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |