🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

I Can't call this function more than once?

#3515
From: Jeff
Date: Wed, 07 Jun 2006 16:27
26 lines
1816 bytes
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

 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
  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: <4486fe87$1@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

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5a83417f22065f8d,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Jeff" <Jeff@nospam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: I Can't call this function more than once?
Date: Wed, 7 Jun 2006 10:27:52 -0600
Lines: 28
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
NNTP-Posting-Host: 198.68.195.241
Message-ID: <4486fe87$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1149697671 198.68.195.241 (7 Jun 2006 09:27:51 -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