🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3516

Re: I Can't call this function more than once?

#3516
From: Boba
Date: Wed, 07 Jun 2006 18:48
40 lines
2099 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:4486fe87$1@newsgroups.borland.com...
> I've build a function that returns the handle to a window who's
caption
> starts with the String passed to it (see code below).  The problem I'm
> having is that when I call it a second time, say in a loop, it throws
an
> EAccessViolation.  Any thoughts?
>
> HWND TfrmMain::FindWindowLike(String strWinText)
> {
>  HWND hWindow; //Window handle
>  char *ptr_chrTitle = ""; //Window title
>

how much memory you think you have pointed by ptr_chrTitle?

>  hWindow = FindWindow(NULL, NULL);   //Start with the first window
>
>  do
>  {
>   SendMessage(hWindow, WM_GETTEXT, GetWindowTextLength(hWindow) + 1,
> (LPARAM)ptr_chrTitle); //Get the window's caption

make sure you don't exceed the memory size pointed by ptr_chrTitle.

>   if (static_cast<String>(ptr_chrTitle).Pos(strWinText) == 1)
//Matches!
> "Visual SourceSafe Explorer --..."
>    return hWindow; //Return the handle
>   else
>    hWindow = GetNextWindow(hWindow, GW_HWNDNEXT);  //Get the handle to
the
> next window
>  } while (hWindow != NULL);  //Search until we run out of windows
>
>  return hWindow; //Return the handle
> }
>
>
Technical Details
Message-ID: <448701e9@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4486fe87$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5a83417f22065f8d
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Boba" <Boba@somewhere.world>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4486fe87$1@newsgroups.borland.com>
Subject: Re: I Can't call this function more than once?
Date: Wed, 7 Jun 2006 11:48:58 -0700
Lines: 42
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 69.22.54.10
Message-ID: <448701e9@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1149698537 69.22.54.10 (7 Jun 2006 09:42:17 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail