Kill current c++ programm process

X

X-Centric

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
 
P

Phlip

X-Centric said:
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".
 
X

X-Centric

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.
 
D

Donovan Rebbechi

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,
 
X

X-Centric

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->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,
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,
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
 
P

Phlip

X-Centric said:
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);
 
H

Howard

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
 
X

X-Centric

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.
 
X

X-Centric

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.
 
X

X-Centric

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 ?
 
H

Howard

X-Centric said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top