WM_COPYDATA data coming across incorrect? Or something..

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?
LVL 4
PalamedesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LRHGuyCommented:
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
Russell LibbySoftware Engineer, Advisory Commented:

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

Regards,
Russell
0
PalamedesAuthor Commented:
LRHGuy, I'll look into that.. thanks


Russell, How do I do that?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Russell LibbySoftware Engineer, Advisory Commented:
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
PalamedesAuthor Commented:
Yeah trying that.. not really making any difference.. infact.. things got worse.. =)
0
Russell LibbySoftware Engineer, Advisory Commented:
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
PalamedesAuthor Commented:

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
Russell LibbySoftware Engineer, Advisory Commented:
Check the definition of float, I believe it corresponds to the Delphi single (which is only 4 bytes)

Russell
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Russell LibbySoftware Engineer, Advisory Commented:
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
PalamedesAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.