for C++ expert advice on VPTR bug!

  • Follow


I have developed an application (FlashIME, www.d2ksoft.com, actually,
it is an system-wide hooked dll) which has to use the shared data
segment to share information between process.

//------------code --------begin
#pragma data_seg("HOOKDATA")     // Make a new section that we'll make
shared
CCompositionWnd g_comp_wnd=0;   //composition window
CCandidateWnd g_cand_wnd=0;     //candidate window
#pragma data_seg()
//------------code --------end

when the program excutes into one of g_comp_wnd's method
get_direction(), it will suspend. The problem is that the
get_direction is simple and the bug sometimes disappear.

//------------code --------begin
class CCompositionWnd:public CImeWnd
{
public:
       virtual int get_direction(void) { return _direction;}
}

class CCandWnd:public CImeWnd
{
public:
       int move_window(CImeWnd* ref_wnd)
       {
          switch(ref_wnd->get_direction()
          {
             ...
          }
       }
}

//test main
int main(void)
{
//now bug will happen SOMETIMES when move_window() calls
get_direction()
   g_cand_wind.move_window(&g_comp_wnd);
}

//------------code --------end

I spend several weeks on this bug ,after assert and trace everything,
the bug still exists.

Last night before I went to sleep, I suddenly realized that for the
object in process-shared-data-segment, the object should not contain
any pointer member!

Of course, when designing CCompositionWnd and CCandidateWnd, I am
already very careful not to assign them any point-data-member.

I suspect there is still some pointer-member in the objects.

Actually , since I use some dynamical-polyphism and vitual function.
maybe the VPTR is the pointer-member which raise the bug?

I delete the CImeWnd (which is the base class of CCompositionWnd and
CCandidateWnd). I also replace dynamical-polyphism with
static-polyphism, (usinag template, of course).

Now seems the bug disppears forever?!

Since I am not a C++ expert and I know little about windows
development, I ask for the C++ experts here to confirm my guess. Is my
guess right? How to expain it in theory?

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply chb_sh 7/26/2004 7:34:10 AM

"redguardtoo" <chb_sh@hotmail.com> wrote in message
news:5b0a428e.0407251933.2a20683f@posting.google.com...

> I have developed an application (FlashIME, www.d2ksoft.com, actually,
> it is an system-wide hooked dll) which has to use the shared data
> segment to share information between process.
>
> //------------code --------begin
> #pragma data_seg("HOOKDATA")     // Make a new section that we'll make
> shared
.....
> Last night before I went to sleep, I suddenly realized that for the
> object in process-shared-data-segment, the object should not contain
> any pointer member!
.....
> Actually , since I use some dynamical-polyphism and vitual function.
> maybe the VPTR is the pointer-member which raise the bug?
.....
> I delete the CImeWnd (which is the base class of CCompositionWnd and
> CCandidateWnd). I also replace dynamical-polyphism with
> static-polyphism, (usinag template, of course).
>
> Now seems the bug disppears forever?!
>
> Since I am not a C++ expert and I know little about windows
> development, I ask for the C++ experts here to confirm my guess. Is my
> guess right? How to expain it in theory?

Your guess that having process-dependent pointers spuggled into another
process (via whatever tech, shared seg, memmap, common messages, pipe, file,
whatever) will harm you is good.

The other guess that your shared segment solution is problem free is not
good.  Read the dox carefully on the shared segments, somewhere it writes
that the system will try to make it shared, but sometimes it will just not
work -- then you'll end up with distinct processes seeing different data in
the supposedly shared segment, and your program will misbehave.  You shall
chose some other method of interprocess communication.  (I'd likely use COM,
it has support for marshalling).

Paul



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Balog 7/27/2004 4:34:37 PM


1 Replies
105 Views

(page loaded in 0.034 seconds)


Reply: