Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Serial Communications

Posted on 2004-04-14
5
Medium Priority
?
559 Views
Last Modified: 2013-11-20
Hi

I am re-jigging some code I have used for some time now and have hit a small
problem.

I have two apps using the same serial comm code. On a call to

OnSerialMsg in the new app I am building

The debugger keeps bringing up the file

C\...\SRC\Intel\CHKSTK.ASM

File Header....

        page    ,132
        title   chkstk - C stack checking routine
;***
;chkstk.asm - C stack checking routine
;
;       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
;
;Purpose:
;       Provides support for automatic stack checking in C procedures
;       when stack checking is enabled.

End File Header


Then as soon as it hits any one of the if statements the debugger jumps to
return 0 and exits the function. I have debugged this code many times
and have never had this happen

LRESULT CSerialDlg::OnSerialMsg(WPARAM wParam, LPARAM /*lParam*/)
{
      CSerialAPI::EEvent eEvent = CSerialAPI::EEvent(LOWORD(wParam));
      CSerialAPI::EError eError = CSerialAPI::EError(HIWORD(wParam));

      if (eError)
            // what a do?

      if (eEvent & CSerialAPI::EEventBreak)
            

      if (eEvent & CSerialAPI::EEventError)
            
      
      if (eEvent & CSerialAPI::EEventRcvEv)
                 
                 ....................


        return 0;
}


Any help much appreciated

LittlePerson
0
Comment
Question by:LittlePerson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 10822516
An error during stack checking normally means that calling conventions don't match. Possible ones are __cdecl, __stdcall or PASCAL. The difference is how they treat arguments to functions: Putting them from left to right or the other way on the stack and who has to cleanup when the function finishes. If the stack is not cleaned up by the called function as the calles expected you will get this error. But writing out of bounds of an array might modify the stack in a way that a check fails on return.

Standard for C/C++ is __cdecl which means right to left pushing of arguments. Callee must clean the stack.
0
 

Author Comment

by:LittlePerson
ID: 10822570
I am not understanding !!!
0
 
LVL 13

Accepted Solution

by:
SteH earned 800 total points
ID: 10822751
To assure that the stack is not altered when returning from a call to a function a value is pushed onto the stack before calling the function and stored into a register. After returning these two values are compared and need to be identical. If not the above mentioned code is called. To get into this situation there are mainly two options:
1) Writing to a memory location using a pointer can modify the stored value. In that case you need to check whether all array indices you use are within bounds reserved for that array.

2) Calling conventions don't match. To find this type of error can be much more tricky since there are several possibilities. Values can be assumed to be put on the stack by value or by address. If their sizes don't match the cleaning up after calling will fail since the amount of data on the stack is different from the amount removed. Check all function declarations and that all header files agree.

Can you post more code?
0
 

Author Comment

by:LittlePerson
ID: 10824052
Thanks for the replies.

I will post more code later as time is tight at the moment. The only change I made
is that instead of writing CString* over the serial communication I am now sending
an unsigned char.

Till later...


Thanks
0
 

Author Comment

by:LittlePerson
ID: 10867595
Thanks again for the reply and sorry for the delay in getting
back to the question. Fortunately the code is performing OK now
(well I have a new problem now - new question to be posted)

Hopefully you can help with this new problem.

Regards
LittlePerson
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 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