Board index » cppbuilder » C++ Builder V5 compatibility with Windows XP

C++ Builder V5 compatibility with Windows XP

Hi everyone,

I have been developing a communications applications and find
that when the application is debugged using the IDE it does not
function the same as it does when the exe file is run directly. I
have tracked the problem to the ReadFile() function which will
only work under the IDE if I use the following.

char RxChar;
ReadFile(..., RxChar, 1, ..., ...);

When I use the line

char RxChar[10];
ReadFile(..., &RxChar[0], 10, ..., ...);

I do not get a compiler or linker error but the function ReadFile()
returns error code 87 which is 'the parameter is incorrect'. How
can the ReadFile() know the difference between the two at run
time?

I am using C++ Builder V5.0 professional with update 1 applied
on a Windows XP machine. I would like to know if the two are
compatible?

I have also experienced other problems where an exe file built
and run on the XP machine does not work, but if it is built on a
Windows 98 machine and then run on the XP machine it works
fine! I can succesfully build and run the same exe file on an NT
machine.

Regards Farmer Jo

 

Re:C++ Builder V5 compatibility with Windows XP


Quote
> char RxChar;
> ReadFile(..., RxChar, 1, ..., ...);

Not correct.  'RxChar' is the value, not the address.  It should be
'&RxChar'.

Quote
> char RxChar[10];
> ReadFile(..., &RxChar[0], 10, ..., ...);

Probably ok but 'RxChar' is the conventional way to do that.  The name of an
array is the address of the first element of the array.  Try it with
'RxChar'.

This is a guess but see if defining this for the project changes things:

_WIN32_WINNT 0x400

Some structures are different sizes and some other things are different if
the program is marked to be 0x500 (for Win2K) or 0x510 (for XP).

I'll be offline until tomorrow morning (east coast time), so won't see any
replies until then.

.  Ed

Re:C++ Builder V5 compatibility with Windows XP


Hi Ed,

Thanks for the reply,

I have got a bit closer to the problem I think. I would seem to be to do
with the
placement of the various communications data structures within the thread. I
did
not mention that the ReadFile() fnuction was being called from its own
thread. I
have found that the ReadFile() returns a failure value depending on where
various
subsequent data declarations are placed. I had placed the following code
after the
ReadFile() function.

DWORD Error;
COMSTAT ComStat;
ClearCommError(CommPortHandle, &Error, &ComStat);

I find that if I move the two data declarations to the beinging of the
thread (before
any executable statements) the problem can be made to go away if a padding
array
is added as follows.

char pad[5];
DWORD Error;
COMSTAT ComStat;

Moving the two declarations outside of the thread does not solve the
problem.

It would suggest that either there is an alignment problem or maybe the size
of the
structures under Windows XP is different to that of Windows 98 as you
mentioned.
I tried what you suggested with the _WIN32_WINNT define but this did not
solve
the problem. I think that the data structure sizes are the same on both
platforms.

Regards
Dave Jones

Re:C++ Builder V5 compatibility with Windows XP


I wish I knew exactly what to tell you to fix the problem.

Check that all you do with the port is in the same thread, that no code
outide of the thread alters or uses data involved in the serial
communications, and that code is in place that checks that the comm port
handle is valid.

Note that when you are asking about serial port issues it is important to
mention if the port is run as overlapped or not.

.  Ed

Re:C++ Builder V5 compatibility with Windows XP


I am using overlapped communications. All API functions that are called are
enclosed
in an error detection if statement that logs any errors to a file if they
occur. Thats how
I was able to determine that the ReadFile() function was failing even when I
added code
that was well beyond the line with the problematic ReadFile(). I have not
had a chance
to work on the code today but will hopefully look at at tomorrow. When I
find out more
I'll reply to the group.

Regards
Farmer Jo

"Ed Mulroy [TeamB]" <e...@mulroy.org> wrote in message
news:3cf38904_1@dnews...

Quote
> I wish I knew exactly what to tell you to fix the problem.

> Check that all you do with the port is in the same thread, that no code
> outide of the thread alters or uses data involved in the serial
> communications, and that code is in place that checks that the comm port
> handle is valid.

> Note that when you are asking about serial port issues it is important to
> mention if the port is run as overlapped or not.

> .  Ed

Re:C++ Builder V5 compatibility with Windows XP


Hi Ed,

Cracked at last. The problem was the values of some of the members in the
overlapped
argument to the ReadFile() function. I carefully read the API documentation
and thought
it was not necessary to initialise the Internal, InternalHigh, Offset and
OffsetHigh members
since they were either reserved or ignored where communications devices were
concerned.
I only initialised the hEvent member to an event handle created using the
CreateEvent()
function.

On running the program I would get an error depending on the placement of
unrelated
variables at the start of the thread.Changing the order would sometimes
allow the
ReadFile() function to successfuly work since by chance the uninitialised
member values
would be valid.

I eventually got round the problem by declaring the overlapped structure as
follows.

OVERLAPPED ReadOverlapped = {0};

Which sets all members values to zero.

I guess the question now is 'what should the four unused member values
really be?' If
anyone knows please share it with me.

Regards
Farmer Jo

Re:C++ Builder V5 compatibility with Windows XP


It's good hearing that you've gotten around the problem.

I can't tell you how those variables are used internally by Windows.  I do
know that it has been standard for as long as I can remember to zero out any
structure you pass to a Windows function (except for needed args of course).
I've never seen that in the documentation as a requirement but have always
done it that way and others seem to do the same.

.  Ed

Quote
> I eventually got round the problem by declaring
> the overlapped structure as follows.

> OVERLAPPED ReadOverlapped = {0};

> Which sets all members values to zero.

> I guess the question now is 'what should the four
> unused member values really be?' If anyone
> knows please share it with me.

Re:C++ Builder V5 compatibility with Windows XP


Many thanks Ed.

Regards Farmer Jo

Other Threads