Kill current c++ programm process

Discussion in 'C++' started by X-Centric, Jun 30, 2005.

  1. X-Centric

    X-Centric Guest

    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
     
    X-Centric, Jun 30, 2005
    #1
    1. Advertising

  2. X-Centric

    Phlip Guest

    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
     
    Phlip, Jun 30, 2005
    #2
    1. Advertising

  3. X-Centric

    X-Centric Guest

    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.
     
    X-Centric, Jun 30, 2005
    #3
  4. On 2005-06-30, X-Centric <> 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/
     
    Donovan Rebbechi, Jun 30, 2005
    #4
  5. X-Centric

    X-Centric Guest

    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
     
    X-Centric, Jun 30, 2005
    #5
  6. X-Centric

    Phlip Guest

    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
     
    Phlip, Jun 30, 2005
    #6
  7. X-Centric

    Howard Guest

    "X-Centric" <> wrote in message
    news:...

    > 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
     
    Howard, Jun 30, 2005
    #7
  8. X-Centric

    X-Centric Guest

    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-Centric, Jul 1, 2005
    #8
  9. X-Centric

    X-Centric Guest

    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-Centric, Jul 1, 2005
    #9
  10. X-Centric

    X-Centric Guest

    The error:
    Access violation .... in module rtl60.bpl
     
    X-Centric, Jul 1, 2005
    #10
  11. X-Centric

    X-Centric Guest

    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 ?
     
    X-Centric, Jul 1, 2005
    #11
  12. X-Centric

    Howard Guest

    "X-Centric" <> wrote in message
    news:...
    > 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
     
    Howard, Jul 1, 2005
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Freddy Fischer
    Replies:
    1
    Views:
    321
    Natty Gur
    Oct 23, 2003
  2. AlexPain

    Java Programm into Systray

    AlexPain, Jul 30, 2003, in forum: Java
    Replies:
    5
    Views:
    1,508
    Eugene Toporov
    Aug 5, 2003
  3. Romeo
    Replies:
    3
    Views:
    377
    Mickey Segal
    Nov 13, 2003
  4. TIM
    Replies:
    6
    Views:
    420
    Christopher Benson-Manica
    Apr 12, 2004
  5. Brian
    Replies:
    1
    Views:
    130
    John W. Krahn
    May 24, 2004
Loading...

Share This Page