CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    What's happen? SetDlgItemText Crash

    Hi!

    What's happen?
    Yesterday, my app work without problem.
    Today, it crashes! The crash occurs at the initialization of a dialog box , at setting data in control with the "SetDlgItemText "instruction.
    I don't understand why today it crashes. Between yesterday and today i don't change the file concerning with dialog. I just add some functions to print, to tile the windows...
    The error messages are :
    "L'instruction 0x758fe" emploie l'adresse memoire "0x8652f" qui ne peut pas etre written".
    "Unhandled exception in powercap.exe (NTDLL.DLL); access violation"

    Somebody has an idea!

    Sandrine


  2. #2
    Join Date
    May 1999
    Posts
    318

    Re: What's happen? SetDlgItemText Crash

    Dont you change anything in your resources or recource.h files (for example control's ID)?

    Do you have some code sample ?



  3. #3
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    Re: What's happen? SetDlgItemText Crash


    I add some items to my menu...
    But i have some controls the ID is a number: Because i have a lot of controls in a dialog box a number is easier to manipulate. They have the number 100 to 196.
    Is it perhaps not a good thing? In the resource.h each ID of a control has a number (#Define IDC_EDIT_NAME 3652). And the first ID control has the number 1000. the ID of dialog box, bitmaps and icons have the numbers from 100 to 300...

    Please help me...

    this is a part od code when it crashes:

    for ( i=0; i<8; i++)
    {

    nID = 100 + ( i*6) + 1; // int nID=>int or UINT
    str.Format("%d", pdu.NbLine[m_PDUIndex + i]);
    SetDlgItemText(nID, str);
    .....
    }



    Thanks a lot

    Sandrine


  4. #4
    Join Date
    May 1999
    Posts
    318

    Re: What's happen? SetDlgItemText Crash

    You must be sure of the ids you are using.

    The resource editor use IDs string. These strings are mapped to numbers in the resource.h.
    So the ids you directly use in your code must be the SAME as the ids in the resource.h that corresponds of the ids string in the dialog.

    If you try to access an non existing id (in the window) then a GPF occurs.

    I think it is poor method of working.

    For example you could try to make an array of ids


    UINT myids={IDC_EDIT1,IDC_EDIT2,IDC_EDIT3};
    for ( i=0; i<siseof(myids)/sizeof(UINT); i++) {
    str.Format("%d", pdu.NbLine[m_PDUIndex + i]);
    SetDlgItemText(myids(i), str);
    .....
    }




    hope this helps






  5. #5
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    Re: What's happen? SetDlgItemText Crash


    You're right: I try to work with an array...

    But my app crashes when i open a dialog box whiwh the ID are correctly defined. You think that my problem is due to these uncertain ID.

    And another question, i have these messages in my debug window:
    "Loaded 'C:\WINNT\system32\KERNEL32.DLL', no matching symbolic information found."
    "Loaded 'C:\WINNT\system32\NTDLL.DLL', no matching symbolic information found."
    "First-chance exception in Powercap.exe (KERNEL32.DLL): 0xC0000005: Access Violation".
    "First-chance exception in Powercap.exe (NTDLL.DLL): 0xC0000005: Access Violation".

    What do they mean?

    Thanks

    Sandrine


  6. #6
    Join Date
    May 1999
    Posts
    318

    Re: What's happen? SetDlgItemText Crash

    Does your error occur if you remove the SetDlgItem code ?
    If yes you must certainly access either an unknown id in the window or a control that don't support SetDlgItem ?
    In this case replace your id computing by real ids of your window. Still crashing ?
    I dont know the exact differences between SetDlgItemText and SetWindowText. Try the second ...

    About your messages : Microsoft Secret World


  7. #7
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    Re: What's happen? SetDlgItemText Crash

    I change my ID but the app crashes always.It crashes after i try to open some dialog box .
    This is the message in the debug window when the crash occurs:

    "HEAP[Powercap.exe]: Invalid Address specified to RtlGetUserInfoHeap( 140000, 77e771e8 )"

    I think i will rebuilt my apply from a backup...

    Just a question:
    I have global pointers. In the OnInitInstance() function, i initialise them with NULL value.
    After, I call a function which return a pointer (address) and affect it to my pointer. Is it correct?
    Example
    * the pointer: int *p;
    * p = NULL;
    * p = thefunction(...); // with int* the function (...)

    Thanks for your replies
    Je suis desesperee!

    Sandrine



  8. #8
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: What's happen? SetDlgItemText Crash

    1) Try a full recompile on your project (Build - Rebuild All). Sometimes too many incremental recompiles and relinks can screw the whole project up.

    2) Before using the ID with SetDlgItemText(), call GetDlgItem(). Test the CWnd pointer returned from that to see if it is NULL. If it is, then you are trying to access a non-existent ID.

    3) Failing that, trace into the SetDlgItemText() call. Follow it through the MFC code and see if you can spot any problems as you go.



    --
    Jason Teagle
    [email protected]

  9. #9
    Join Date
    May 1999
    Posts
    318

    Re: What's happen? SetDlgItemText Crash

    About your pointer this seems !VERY! incorrect.

    If i am correct you do this :


    int *fct(...) {
    ...}

    int *i=NULL;
    // HERE IS A ERROR
    *i=fct();
    // i DONT contain now the returned pointer
    // but you try to put the value of the returned pointer in NULL address (->GPF)
    // YOU MUST DO THIS :
    i=fct();
    // NOW i IS EQUAL TO THE RETURNED POINTER




    I dont what you want to do.
    If you want to keep a pointer to integer in i then do as described above.

    Another thing.
    Dont forget that a function MUST NOT return a pointer to a local variable

    Here is an example that fct MUST NOT do.

    int *fct() {
    int i;
    // VERY VERY BAD STUFF
    return &i;
    }




    hop this helps






  10. #10
    Guest

    Re: What's happen? SetDlgItemText Crash


    Dear Sandrine,

    Going through your discussions, I think that a little more time should be taken
    and the whole code (related to the dialog under question) should be rewritten.
    It is sounding a magnum opus, but if you just fix the Dialog ID and the control
    IDs carefully, your code will stabilize. You may not have to rewrite the code
    fully. But this extra time you spend now will buy you a lot of peace of mind
    later.

    In general, it is a good practice to use control IDs through the resource. For a
    large system, the chances of a Dialog ID duplication or control ID duplication
    (in the same dialog) is very high, specially if you are attaching control ids from
    your source program.

    Jason's suggestion of a full compile (Rebuild All) is good; it may help. But if
    there is a ID duplication, a code walk-through is imminent and the sooner it
    is done, the better.

    In answer to Eric's question:
    SetDlgItemText() sets text for the control in a dialog; e.g. edit control,
    radio button, push button etc. It assumes a valid Dialog ID/handle and
    a valid control ID/handle in that dialog.
    SetWindowText() applied to a dialog will set the text in its title bar. It only
    assumes a valid Dialog ID/handle.

    If you really want to use dynamic control IDs, then create the controls
    dynamically, too. For instance, you may have 20 edit boxes in a sin

  11. #11
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    Re: What's happen? SetDlgItemText Crash



    Sorry, in my previous mail, i use "*" to mark the different steps...

    This is what i do:
    - First i declare a global pointer and assign a NULL value: MyPointer = NULL;


    - After i call my function and assign the return adress to my pointer: MyPointer = MyFunction();

    My pointer is derived of the CMDIFrameWnd class and my function is called when i want to create a new Wnd and the returned value is the returned value of the CMDIChildWnd::Create() function.

    I think that it's correct, no?

    I manage to find the mean of some "access violation messages": cause i manipulate empty strings.

    But my initial problem is not resolved...even if i rebuilt my application...

    Thanks

    Sandrine



  12. #12
    Join Date
    May 1999
    Posts
    318

    Re: What's happen? SetDlgItemText Crash

    CMDIChildWnd::Create returns a BOOl not a pointer.
    Where do you alloate your mdi child window, in function local stack or in global heap ?

    Finally the suggestions of the two others to make some debug and rebuild sound find to me.



  13. #13
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    Re: What's happen? SetDlgItemText Crash


    Yes, you're right for CMDIFrameWnd... Stupid girl!

    I alloate my MDI window in the OnInitInstance() function... But, i just assign the NULL value, not use new because i don't know where free it. In the destructor,it doesn't work...


  14. #14
    Join Date
    May 1999
    Posts
    318

    Re: What's happen? SetDlgItemText Crash

    Its good you found the problem source.
    But something sounds bad to me.
    You allocate a general CMDIFrameWnd and you have a function that call create on this object.
    Does this mean you call your function several times and so you call several times Create method of the same CMDIFrameWnd object ?

    good luck






  15. #15
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    Re: What's happen? SetDlgItemText Crash


    Re:
    You allocate a general CMDIFrameWnd and you have a function that call create on this object.
    Does this mean you call your function several times and so you call several times Create method of the same CMDIFrameWnd object ?

    Yes...

    ---
    You know, now my appli crashes when i try to open some dialog boxes. With the debug , i follow the instructions and it crashes when it calls the CreateDlgIndirect() function.
    And i have the following message :
    "HEAP[Powercap.exe]: Invalid Address specified to RtlGetUserInfoHeap( 140000, 77e771e8 )
    First-chance exception in Powercap.exe (NTDLL.DLL): 0xC0000005: Access Violation."
    What's this function? What does it do?...

    Sandrine


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured