?
Solved

WM_COPYDATA data coming across incorrect?  Or something..

Posted on 2004-11-14
10
Medium Priority
?
611 Views
Last Modified: 2010-04-05
Hey gang,

I have been developing an application that works with a game.  It uses WMCOPYDATA to send information back and forth between the two apps.  (though right now its strictly one directional.. from the game to my application but thats an aside)..

The documentation for this process is all written in C++ and I'm not much of a C++ programmer..  

The game sends some event data to my application through WM_COPYDATA and my program then processes that data.  At this time, for some reason, I don't get all the data that is supposed to be coming over the WM_COPYDATA message.

As per this thread; http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20434236.html

I have it working, I thought.  But for some reason, a lot of stuff isn't showing up, OR is showing up incorrectly.   WM_COPYDATA uses a pointer reference so I'm not sure why some of this stuff is wrong.

I had to convert the C++ code below to Delphi.. as below;

//C++
typedef struct ExternalEventData    {
     unsigned long     valid_fields;
     ExternalEventID     event_id;
     char          text_message[MAX_EED_TEXT_LENGTH];
     TODOBJECT          object_identifier;
     TODPOSITION     theatre_position;
     TODISLAND          island_identifier;
     TODPLAYER          player_identifier;
     } ExternalEventData;

// Delphi
type
  ExternalEventData = record
    valid_fields: Cardinal;
    event_id: ExternalEventID;
    text_message: array [0..MAX_EED_TEXT_LENGTH-1] of Char;
    object_identifier: TODOBJECT;
    theatre_position: TODPOSITION;
    island_identifier: TODISLAND;
    player_identifier: TODPLAYER;
  end;

For some reason though, Some of the data is coming over in the wrong place.. For example I'm getting data that should be part of TODISLAND, as part of TODPLAYER..etc..


I know the game is sending the data correctly because the programmers of the game also sent me a test application that gets the data and it works just fine..

So.. how do I test this.. How do I test for each part?  Is there any way I can just convert the whole thing to text and know what belongs to what?

I mean this is frustrating and there doesn't appear to be anyway to test it..


It seems like of the record, all those that are not custom types, work fine.  
Those that are custom types (TODObject, TODPosition..etc) they are wrong or scewed so that their data shows up incorrectly..

I'm a loss..

Thoughts?
0
Comment
Question by:Palamedes
  • 5
  • 4
10 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12580343
I'm guessing the problem is in a datatype.

For example, are "unsigned long" and "cardinal" really the same thing? I would have used "longword" for the delphi side. The actual sizeof "cardinal" depends on the compiler and cpu.

So, that said, I would double check all the c-to-delphi record translations, and see if any have the wrong size declaration, which would make data appear in a "different" location.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 12581039

Have you tried declaring your stuct as "packed record"? This is most likely casuing the data alignment problem

Regards,
Russell
0
 
LVL 4

Author Comment

by:Palamedes
ID: 12581044
LRHGuy, I'll look into that.. thanks


Russell, How do I do that?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:Russell Libby
ID: 12581174
type
  ExternalEventData = packed record // <- packed record vs record
    valid_fields: Cardinal;
    event_id: ExternalEventID;
    text_message: array [0..MAX_EED_TEXT_LENGTH-1] of Char;
    object_identifier: TODOBJECT;
    theatre_position: TODPOSITION;
    island_identifier: TODISLAND;
    player_identifier: TODPLAYER;
  end;


Russell
0
 
LVL 4

Author Comment

by:Palamedes
ID: 12581182
Yeah trying that.. not really making any difference.. infact.. things got worse.. =)
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 12581191
Ask the C guys what the enum size is (type size). I bet its 4....
If so, then the packed keyword would throw it off by another byte. Check your other q and add the {$Z4} directive before the set type declaration.

Russell
0
 
LVL 4

Author Comment

by:Palamedes
ID: 12581210

Okay.. so my ExternalEventID type is working now.. (It wasn't before)..

But still getting erronious data in some areas..

This for example;

typedef struct TODPOSITION
      {
      float x, y, z;                  // X/Y/Z position within grid square
      long grid_x;
      long grid_y;                  // Grid square position
      } TODPOSITION;

I converted as such;
  type TODPosition = record
      x, y, z   : double;
      grid_x    : longint;
      grid_y    : longint;
    end;

Is this wrong?

This is some of the data that I'm not getting through correctly..
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
ID: 12581246
Check the definition of float, I believe it corresponds to the Delphi single (which is only 4 bytes)

Russell
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 12581256
From my docs that I have handy

unsigned long 4 unsigned long int 0 to 4,294,967,295
enum * none Same as int
float 4 none 3.4E +/- 38 (7 digits)
double 8 none 1.7E +/- 308 (15 digits)
long double 10 none 1.2E +/- 4932 (19 digits)

// Delphi
Single      1.5 x 10^–45 .. 3.4 x 10^38      7–8      4
Double      5.0 x 10^–324 .. 1.7 x 10^308      15–16      8

----

Russell
0
 
LVL 4

Author Comment

by:Palamedes
ID: 12581380
Thats it!  I was declaring an 8 byte float as opposed to a 4 byte..

It should have been a single!  

OH man.. a load off..  Thanks a bunch Russel.. I appreciate it..

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question