469,955 Members | 2,457 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Kill current c++ programm process

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

Jul 23 '05 #1
11 4315
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
Jul 23 '05 #2
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.

Jul 23 '05 #3
On 2005-06-30, X-Centric <ie*@specialfruit.be> 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/
Jul 23 '05 #4
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

Jul 23 '05 #5
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
Jul 23 '05 #6

"X-Centric" <ie*@specialfruit.be> wrote in message
news:11*********************@o13g2000cwo.googlegro 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

Jul 23 '05 #7
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.

Jul 23 '05 #8
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.

Jul 23 '05 #9
The error:
Access violation .... in module rtl60.bpl

Jul 23 '05 #10
when i execute the above code twice (click the button twice) it sais
(added a watch) that ListviewSpeed (Tlistview) is an undefined symbol.
what does this mean ?

Jul 23 '05 #11

"X-Centric" <ie*@specialfruit.be> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.


I don't think &Buffer is correct. Either just Buffer, or &Buffer[0].

Did you remove the "delete Buffer" code?

Why are you using "new" and "delete" on MS (new twice, deletes commented
out), and on Registry? Also, why are yuo calling delete on item (once)? It
looks like the code you're using grants ownership to ListViewSpeed2. If
it's your job to delete those items, this surely isn't the place to do it
(that belongs in a destructor or simlar cleanup code), and you'd need to do
it for all items previously added, not just once.

Once you get these items fixed, the error *might* go away. The symptoms
look to me like you've trashed memory previously (during the processing of
the first button click).

Before you try getting GUI code to work right, you should really get a good
book on C++ and read up on how to use arrays and pointers. Then write some
simple console apps, using std::cin and std::cout to do simple text I/O.
And avoid using pointers unless and until you need them. In your code,
there's no reason for Registry or MS to be pointers, when they can just as
well be objects (e.g., "TRegistry Registry;").

-Howard
Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Bob Swerdlow | last post: by
3 posts views Thread by pattanawadee | last post: by
5 posts views Thread by Dino Buljubasic | last post: by
4 posts views Thread by iwdu15 | last post: by
4 posts views Thread by Richard Rossel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.