Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Kill current c++ programm process

Reply
Thread Tools

Kill current c++ programm process

 
 
X-Centric
Guest
Posts: n/a
 
      06-30-2005
hi,

because I always get an EAccessViolation error when i try to quit my
program, I want to kill the process of it everytime it finishes its
task.
and then rerun it.
can someone tell me how to do this ?

ief

 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      06-30-2005
X-Centric wrote:

> because I always get an EAccessViolation error when i try to quit my
> program, I want to kill the process of it everytime it finishes its
> task.
> and then rerun it.


If this is your own program, and you have a bug, fix it.

Each time you put off a fix, you push down the quality of your code, and the
quality of your development process. The lower quality gets, the longer you
will take to add each new feature. This path is not sustainable.

If you can't fix it, rewrite the program from scratch, and this time use
unit tests and decoupled modules.

> can someone tell me how to do this ?


Google for my street name and "killall".

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand


 
Reply With Quote
 
 
 
 
X-Centric
Guest
Posts: n/a
 
      06-30-2005
I think the crash comes from a component i used.
which is shareware.
I had to write a program which converts some data from a program to a
new version.
this data are properties written by a stream writer in a file.
in the new version of that program they use another component to list
the data, namely the TspSkinListview in stead of the TlistView.
so i can't just copy files.
everything is working, except, I can only fill the lists once, seconc
time i get error and when I quit the program, i get the same
EaccessViolation error.

 
Reply With Quote
 
Donovan Rebbechi
Guest
Posts: n/a
 
      06-30-2005
On 2005-06-30, X-Centric <(E-Mail Removed)> wrote:
> I think the crash comes from a component i used.
> which is shareware.
> I had to write a program which converts some data from a program to a
> new version.
> this data are properties written by a stream writer in a file.
> in the new version of that program they use another component to list
> the data, namely the TspSkinListview in stead of the TlistView.
> so i can't just copy files.
> everything is working, except, I can only fill the lists once, seconc
> time i get error and when I quit the program, i get the same
> EaccessViolation error.


Have you looked at this with a debugger ? If you (after debugging, of course)
believe it's the component that is the problem, can you reproduce the problem
with a very simple example, which you can then bug the author about ?

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
 
Reply With Quote
 
X-Centric
Guest
Posts: n/a
 
      06-30-2005
I use borland cbuilder to write/debug the prog.
don't get must smarter with this information.
it allways crashes on this line:
MS->WriteComponent(ListViewSpeed2);

but only when i puch the button twice,
here is my full code.
TMemoryStream *MS = new TMemoryStream;
TRegistry *Registry = new TRegistry;
void *Buffer[50000]; // Make buffer large enough
int BytesRead = 0; // Amount of bytes read into stream
TListItem *item; // item used to add in new format
digit d;

// Load Template file for new data
MS->LoadFromFile("ListViewSpeed2352");
MS->Seek(0,soFromBeginning);
MS->ReadComponent(ListViewSpeed2);

// Settings required for Phonemanager to work correctly
ListViewSpeed2->PopupMenu = MainForm->SpeedMenu1;
ListViewSpeed2->LargeImages = MainForm->NewSpeedImageList;
ListViewSpeed2->SmallImages = MainForm->NewSpeedImageListSmall;
ListViewSpeed2->HScrollBar = MainForm->SpeeddialHScrollBar;
ListViewSpeed2->VScrollBar = MainForm->SpeeddialVScrollbar;
ListViewSpeed2->UseSkinFont = true;
MainForm->SpeedMenu1->AutoPopup = true;

// Read the data to convert from the registry
//delete MS;
MS = new TMemoryStream;

Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey("Software\\Avaya\\IP400\\PhoneManager",
false);
BytesRead = Registry->ReadBinaryData("ListViewSpeed", Buffer,
sizeof(Buffer));
Registry->CloseKey();

MS->Write(Buffer, BytesRead);
MS->Seek(0,soFromBeginning);
MS->ReadComponent(ListViewSpeed);

// Add the loaded items to the new skinlist, with required
subitems
for (int i=0; i<ListViewSpeed->Items->Count;i++)
{
// Only import external numbers (true)
if (chkDel->Checked)
{
// Check if number is external (3 digits =
internal)
std::string a =
ListViewSpeed->Items->Item[i]->SubItems->GetText();
std::string::iterator ai =
std::find_if(a.begin(), a.end(), d);
int nCount = std::count_if(ai, a.end(), d);

if (nCount > 3)
{
// Add External number
item =
ListViewSpeed2->Items->AddItem(ListViewSpeed->Items->Item[i],
ListViewSpeed2->Items->Count);

item->SubItems->Add("");
item->SubItems->Add("");
item->SubItems->Add("");
item->SubItems->Add("");
}
}
else
{
// Allso import internal number(false)
item =
ListViewSpeed2->Items->AddItem(ListViewSpeed->Items->Item[i],
ListViewSpeed2->Items->Count);

item->SubItems->Add("");
item->SubItems->Add("");
item->SubItems->Add("");
item->SubItems->Add("");
}
}

//delete MS;
MS = new TMemoryStream;

// Set old list invisible
// Set new list visible because it writes the property to the
file
ListViewSpeed->Visible = false;
ListViewSpeed2->Visible = true;
ListViewSpeed2->ViewStyle = vsList; // Show items in a
list(not possible with phonemanager)

// Write properties to a file
MS->WriteComponent(ListViewSpeed2);
MS->SaveToFile("ListViewSpeed2__" + txtName->Text);

ListViewSpeed2->Visible = false;

lblStatus->Caption = "All Done.";

//delete MS;
delete item;
delete Buffer;
delete Registry;

i'm not a very experienced c programmer, so, srry if code is not good.

ief

 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      06-30-2005
X-Centric wrote:

> void *Buffer[50000]; // Make buffer large enough


Do you really need 50,000 pointers to void?

> BytesRead = Registry->ReadBinaryData("ListViewSpeed", Buffer,
> sizeof(Buffer));


Those are typically character buffers.

> delete Buffer;


Here's a big problem. Never 'delete' anything you did not 'new'.

In general, you need to step thru your code and add an assert() to each
juncture. Check that everything did what you think it did. Even assertions
as simple as this:

assert (BytesRead > 0);

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand


 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      06-30-2005

"X-Centric" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...

> void *Buffer[50000]; // Make buffer large enough


> BytesRead = Registry->ReadBinaryData("ListViewSpeed", Buffer,
> sizeof(Buffer));


I take it ReadBinaryData wants a void* for the second parameter? That does
not mean that the array should be an arry of void* pointers! It just means
it's expecting an address (and doesn't particularly care what that address
points to).

You probably just want to declare an array of char, not an array of void*.
(But you might check the documentation for that function call to be sure.)

> delete Buffer;


You're deleting an object that you didn't create via "new". That's not
allowed.

>
> i'm not a very experienced c programmer, so, srry if code is not good.
>
> ief
>


(By the way, we're discussing C++ here, not C.)

-Howard



 
Reply With Quote
 
X-Centric
Guest
Posts: n/a
 
      07-01-2005
I mean c++ ofcourse
I'm not used to using pointers, and array's etc.
i made it this way, because this was i thought it should be, and it
worked, expect for the error ...

thx for all the help, will try it later on today.

 
Reply With Quote
 
X-Centric
Guest
Posts: n/a
 
      07-01-2005
changed code to this:

char Buffer[10000];
BytesRead = Registry->ReadBinaryData("ListViewSpeed", &Buffer,
sizeof(Buffer));

maybe this is more correct, but my main problem is still this error i
get.
I just can't figure out how it happens.

 
Reply With Quote
 
X-Centric
Guest
Posts: n/a
 
      07-01-2005
The error:
Access violation .... in module rtl60.bpl

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
KILL BABY KILL widescreen drsd2kill DVD Video 3 11-29-2004 09:36 PM
Bava's KILL BABY KILL widescreen drsd2kill DVD Video 0 11-27-2004 12:04 AM
Want to kill current process then restart Brian Perl Misc 1 05-24-2004 05:16 AM
Access to process memory from external programm TIM C Programming 6 04-12-2004 01:17 PM
Help!!! Loosing SessionState when calling external programm Freddy Fischer ASP .Net 1 10-23-2003 05:32 PM



Advertisments