Click here to Skip to main content
Email Password   helpLost your password?

Introduction

This demo demonstrates how to send / receive WM_COPYDATA messages between a collection of C++ and C# programs.

Why use WM_COPYDATA?

Traditionally WM_COPYDATA was used to send a limited amount of data between processes on the same machine. It is still desirable to interoperate this way even with the rise of .NET. .NET Remoting is out of the scope of this demo. This demo is intended for people like myself that are dealing with legacy environments.

The demo consists of four programs and one DLL. Two programs are written in C++ (MS Version 5.0) and two are written in C# (using .NET 2003). A C++ exe and C# exe will send the structure shown below to a C++ and C# receiving program.

struct sTagData
{//this is the structure that will be sent (copied) by the WM_COPYDATA

private:
    char szTag[ciMaxTag];
    char szData[ciMaxData];
}

The DLL was written in VC 5.0 and it wraps the WM_COPYDATA message.

Additionally, the DLL provides a uniform way of :-

  1. Protecting the receiving application from third party processes that may be unwise enough to HWND_BROADCAST the WM_COPYMESSAGE.
  2. Allows incoming messages to be limited to specific senders either by handle or sender id.
  3. Optional use a crude bitwise encryption to discourage hackers from spying on messages.

Unzip using the full paths to your C drive. The result should be the shown directory structure.

To use the demo, open folder build and click on all 4 executables. Click on the send buttons in the FROM apps and the message will appear in the TO apps. Both FROM programs are document to show how to use the DLL�s interface. Likewise, both TO programs are documented in their WindowProc()�s to show how to receive the data.

Platforms supported

These programs have only been tested on Windows XP.

Other facts

Philip McGahan is the sole creator of this demo. No part of it has been plagiarized from other sources. Any party may use all or part of this demo with out credit or reference to Philip McGahan.

Lastly, it is only fair to tell my reader that I am very new at C#. I did try to use C# to build the DLL. But beyond never getting the data to come across with out junk at the end of the string. I was not comfortable with having to setup unsafe blocks. The whole thing just seemed clumsy. When or if I get better at C#, I will revisit this issue.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralI have an error
hjhk456465
22:40 20 Apr '09  
The code is simple but it doesn't works in my project.
I have an error in the line:

iResult = WmCpyDta_SendMessage_sTagData(ProcessHandle.ToInt32(), 0, strTag,strData);

BadImageFormatException HResult: 0x8007000B
The windowHandle is ok and the value of strTag is 'c:\test.obl' and of strData is ''
Can somebody help me?
Thanks a lot.
GeneralHelp please!
rufj
21:04 5 May '08  
After I run the From_C and To_C_Sharp, and click "ping - "button, it gives an error message:

Additional information: Unable to load DLL 'WmCpyDta.dll': (Exception from HRESULT: 0x8007007E)

Could you so kind to show me how to make it work?

Thanks

davisFrown

nothing can hold me back from my strong will when i want to it

GeneralRe: Help please!
McGahanFL
3:37 6 May '08  
It has been many years since I wrote this.
First, get the binaries and extract them using path information to c:\test\
this should give you a path structure of c:\test\build.
Once you have done this, do the sample apps work?

Also check your system for another copy of Wmcpydta.dll. DLL-s are not assemblies, so the 1st copy found is the copy used. Maybe you have another dll by some other vendor by the same name.


pmcgahan@hteinc.com
GeneralRe: Help please!
rufj
0:03 7 May '08  
Thanks your timely replay, I will try it at later time. Wink

nothing can hold me back from my strong will when i want to it

AnswerRe: Help please!
Alexey Plotnikov
5:08 21 Nov '08  
Excellent work, as for me.
Just tryed "From_C and To_Sharp" and "From_Sharp and To_C"
Generalproblem
modream
1:03 5 Nov '07  
if I create a new class in the FROM_C project and include "wmcpydta.h" in it, I got a linker error
that object already defined (functions declared in extern "c")
How can I avoid it ?
I tried including "wmcpydta.h" in stdafx.h and the same thing....
Generalexcellent article
deepikakethireddy
1:00 31 Oct '07  
perfect article with all its scope and excellent presentation....Smile
GeneralVery nice
Shato
11:40 16 Apr '07  
Cool Been looking for samples on this.Great job thanks.
GeneralGreat job
J.Q.C.
12:13 13 Aug '06  
Very great!
GeneralExcelent
ellolazo
5:43 13 Jun '06  
an excelent work with amazingly good explanation. the best job with COPYDATA that i see
tnks

----LOLO----
-------------
<<Argentina>>
-------------
GeneralGood job
selb613
2:54 26 May '06  
Thanks. This is exactly what I was looking for. Smile
GeneralGreat Job!
ciaoroma
6:33 18 Feb '05  
The code is exactly what I needed.

ciaoroma
GeneralAwesome. Just what I needed ! However ...
Dan Clark
7:21 4 Nov '04  
Your code definately was exactly what I have been searching for, however, I wish you explained more in your article for the average person, instead of dumping your code in it and leaving a brief description.
I still gave you a 4 though !




My kickass website !


@{${$dan}{c}{clark}}[1]



Last Updated 27 Oct 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010