LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Send data to other Windows application via WM_COPYDATA

Solved!
Go to solution

Hi EWiebe,

 

Well, now I can see the functions calls in LV code  but I hit the next hurdle - when sending WM_COPYDATA messages (with SendMessage) very often the message  is not received on the target application. The misbehaviour rate varies in time from one lost message on every two ones  to 10 lost messages on one received message.

 

Before (without using the LV_helper.DLL) my LabView program was calling directly the user32.dll SendMessage methods and I never had problems in receiving the message in the target app, only the the information in lpData was never correct. 

 

I modified the code of LV_Helper.DLL to return the pointer to the located application window - the value is identical to the value from user32.dll / FindWindowA. This means the LV_Helper.DLL finds always the target window but somehow the messages is not arriving on destination.

 

I remember I saw somewhere on the forum how they use a loop to send Windows messages - repeat several times until it passes. It sounds like bad and desperate patch of the problem...

 

Some idea what I'm doing wrong and why sometimes the messages are missing (sent but not received on target app side)? Thanks.

 

Best regards,

Luben

 

 

0 Kudos
Message 11 of 13
(742 Views)

Hi,

 

I found the problem - in the LV_Helper.cs for x64 machines dwData is 8 bytes and the the code should be:

public struct COPYDATASTRUCT
{
[MarshalAs(UnmanagedType.I8)]
public Int64 dwData;
[MarshalAs(UnmanagedType.I4)]
public int cbData;
[MarshalAs(UnmanagedType.SysInt)]
public IntPtr lpData;
}

Once everything runs correctly I'll upload the code and the DLL

 

Message 12 of 13
(735 Views)
Solution
Accepted by topic author peter111

As I promised here is the DLL for wrapping WM_COPYDATA messages, the code was tested thoroughly on x64 machines and never failed - LabView can send any data (strings, arrays, structures) by using flatten to string. DLL was compiled in VS 2013, credentials and special thanks to EWiebe who brought the main code. 

For the DLL - unzip the file and change the extension to DLL, you need to add it into LV code as .NET node, not as standard DLL call node.

Download All
Message 13 of 13
(710 Views)