user3733593
user3733593

Reputation: 13

Program runs smoothly, but debugging fails due to access violation at CreateWindowW (my Quess)... how is that possible?

Hy, and welcome to the (surely 500.) question for help due to debugging issues.

First on, i have to say that this is my first attempt to create a programm. Im not new, i am newest to coding, never done it bevore.

** Is it possible to debug multi threaded Apps in a simple fashion?

If someone is thinking "hey, why is he using c/Winapi, ther are better ways to do that" i can only answer.. because the dll for my I/O card is written in c and i am an engineer, not a coder/programmer.

My problem is, that when i run my app (a programm that reads data from virtual Comport and stores it as txt), everything apperas to be fine. But when i use the debugger, i get following Error at the very fisrt CreateWindowW call.

I am running Window7 x64, using multithreaded programming and do have no idea what the debugger want to tell me. Is it possible to run the Winapi32 stuff in x64 surrounding propperly?

** I am using Pelles-C, and i am having troubles to figure out how to do what the debugger want to tell me. he uses to say "enter .exr 0000000000000008BBB0 for the exceptiom record", but i dont have aclue how to get the .exr working, nor where to place the command. I am truly sorry for stealing your time, but im stuck with this problem for more than a wee, bevore opening up this thread.

ODS: An Access Violation occurred in "C:\Users\dhin\Desktop\Ver11\CSR-Messung HB628.exe" :

ODS: The instruction at 0000000075094D62 tried to read from

ODS: an invalid address, 0000000000000010

ODS: * enter .exr 000000000008BBB0 for the exception record

ODS: * enter .cxr 000000000008B6C0 for the context

ODS: * then kb to get the faulting stack

Exception: C000041D

In the debuggers variables section, it sais that hwnd1 (Handle of the main Window) has adress 00000000 ... is that a bad sign?

Here is the piece of code it occures in

   #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <process.h>

    #include "Procs.h"
    #include "Res.h"

    #define My_Icon 1

    //_Generierung der Fenster______________



    HWND hwnd1;
    HANDLE getmutex,writemutex,paintmutex,readmutex;
    MSG msg;
    HINSTANCE hInstance;
    short int compare,AmountOfDatapointBufferint;
    HBRUSH syst;
    void * lpParam;

    int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
    {
    WNDCLASSW main1;    
                  main1.hInstance           =   hInstance;                      // Instanz
                  main1.style               =   CS_HREDRAW | CS_VREDRAW ;       // das fenster wird bei Vergrößern neu gezeichnet (später aber gesperrt &~WS_THICKFRAME macht das kein Rahmen zum vergrößern da ist)
                  main1.cbClsExtra          =   0;                              
                  main1.cbWndExtra          =   0;                              
                  main1.hbrBackground       =   GetSysColorBrush(COLOR_3DFACE); // Hintergrundaret/farbe
                  main1.lpszMenuName        =   NULL;                           // Pop-down menü -> aus
                  main1.hCursor             =   LoadCursor(NULL, IDC_ARROW);    // Cursor -styles
                  main1.hIcon               =   LoadImage(NULL, "MyIcon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);// Icons --


    //____________________________________________________
                  main1.lpszClassName       =   L"Anzahl_der_Messaufbauten_angeben";    
                  main1.lpfnWndProc         =   AnzProc;

                  if(!RegisterClassW(&main1))                               
                    { 
                    MessageBox(NULL, TEXT("Fehler beim Registrieren der ''Anzahl_der_Messaufbauten_angeben'' Fensterklasse!"), NULL, MB_OK | MB_ICONERROR); 
                    return (0); 
                    } 


    //__________________________________________________________
                main1.lpszClassName         =   L"Graph";   
                main1.lpfnWndProc           =   SecProc;    

                if(!RegisterClassW(&main1))                                 
                    { 
                    MessageBox(NULL, TEXT("Fehler beim Registrieren der Graph Fensterklasse!"),NULL, MB_OK | MB_ICONERROR); 
                    return (0); 
                    }


    //___________________________________________________
                    main1.lpfnWndProc           =   MainProc;                       
                    main1.lpszClassName         =   L"CSR_Messung_V_1.0";   

                    if(!RegisterClassW(&main1)) 
                        { 
                        MessageBox(NULL, TEXT("Fehler beim Registrieren der MAIN - Fensterklasse!"), NULL, MB_OK | MB_ICONERROR); 
                        return (0); 
                        } 
                    compare=3;//Standard - Schreibt Formatiert und Unformatiert!
                    AmountOfDatapointBufferint=3; //Standard : 3 Kanäle

                    hwnd1 = CreateWindowW(L"CSR_Messung_V_1.0",L"CSR_Messung_V_1.0",WS_POPUPWINDOW &~WS_THICKFRAME |WS_VISIBLE ,0,0,835,585,NULL,(HMENU)0,hInstance,NULL);


                    ShowWindow (hwnd1, SW_SHOWNORMAL);                  
                    UpdateWindow(hwnd1); 

    //_________________________________________________________
        //Initialisiert die Mutex'es


    etmutex=CreateMutex(NULL,FALSE,"get");              
        readmutex=CreateMutex(NULL,FALSE,"val");            
        writemutex=CreateMutex(NULL,FALSE,"write");         
        paintmutex=CreateMutex(NULL,FALSE,"paint");


    //___________________________________________________
    while (GetMessage(&msg,hwnd1,0,0))
        {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        }
    return (int) msg.wParam;                                
    }

I am wondering why this is happening, allthough the compiler does not even complains about anything. The CALLBACK functions are in another sheet, connected through the proc.h file. I do not chant anything, because i read that this causes nothing but troubles when not done properly.

Therefore my question is, why is the debugger stoping at line 75, the CreateWindowW command??

Thanks for your time and help!

PS: here is the CALLBACK WndProc stuff:

        LRESULT CALLBACK MainProc(HWND hwnd1, UINT msg, WPARAM wParam, LPARAM lParam); 
    // is the main window

    The other two are of equal design, theyr important part of the inner structure is:


switch(msg) 
    {

    break;
    case WM_CREATE:
        {   
// The Main-window is visible, the Graph not, this is indicated by iHide=1;
        iHide=1;

//_________________________________________________________________________________________________________________________________________________________________________________
// Groupbox-Frames
        iSet=0;              
        while(iSet<4)
            {
            GruppenBox[iSet]=CreateWindowW(L"button", L"Start",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_CENTER,(20 + (iSet * 160)), 50, 150, 430, hwnd1, (HMENU) iSet, NULL, NULL);
            iSet=iSet+1;
            }               
        GruppenBox[16]=CreateWindowW(L"button", L"Comport Nr.",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_CENTER,20 ,490,150,80, hwnd1, (HMENU) iSet, NULL, NULL);
        GruppenBox[15]=CreateWindowW(L"button", L"Messwerte (N)",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_CENTER,660 ,50,150,430, hwnd1, (HMENU) iSet, NULL, NULL);
        GruppenBox[18]=CreateWindowW(L"button", L"",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_CENTER,180 ,490,630,80, hwnd1, (HMENU) iSet, NULL, NULL);
        GruppenBox[19]=CreateWindowW(L"button", L"",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_CENTER,-10 ,-20,900,54, hwnd1, (HMENU) iSet, NULL, NULL);
//_________________________________________________________________________________________________________________________________________________________________________________
// Measurement-values-display-boxes
// Boxes for mV-formated data
        iSet=0;             
        while(iSet<AmountOfDatapointBufferint)
            {
            MeasvalueC[iSet]=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILD|WS_VISIBLE| ES_CENTER,515,(80+(iSet * 50)),120,30,hwnd1,(HMENU)0,NULL,NULL);
            iSet=iSet+1;
            }   
// Boxes for Newton-formated data           
        iSet=8; 
        while(iSet<AmountOfDatapointBufferint+8)
            {
            MeasvalueC[iSet]=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILD|WS_VISIBLE| ES_CENTER,675,(80+((iSet - 8) * 50)),120,30,hwnd1,(HMENU)0,NULL,NULL);
            iSet=iSet+1;
            }
//_________________________________________________________________________________________________________________________________________________________________________________
// Checkboxes for CHannel choosing
        iSet=1;         
        while(iSet<AmountOfDatapointBufferint+1)
            {
            CheckBox[iSet]=CreateWindowW(L"button",L"",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_PUSHLIKE,34,(80 + ((iSet-1) * 50)),120,30, hwnd1, NULL,0,0);
            iSet=iSet+1;
            }    
//_________________________________________________________________________________________________________________________________________________________________________________
// Buttons

        Knopf[1]=CreateWindowW(L"button",L"Start",WS_VISIBLE | WS_CHILD | ES_CENTER ,187,507,100,55, hwnd1, (HMENU) 2,0,0); 
        Knopf[5]=CreateWindowW(L"button",L"x",WS_VISIBLE | WS_CHILD | BS_CENTER | ES_CENTER  ,805,5,23,23, hwnd1, (HMENU) 2,0,0);
        Knopf[2]=CreateWindowW(L"button",L"Halt",WS_VISIBLE | WS_CHILD | ES_CENTER ,355,507,100,55, hwnd1, (HMENU) 2,0,0);      
        Knopf[3]=CreateWindowW(L"button",L"Weiter",WS_VISIBLE | WS_CHILD | ES_CENTER ,530,507,100,55, hwnd1, (HMENU) 2,0,0);
        Knopf[4]=CreateWindowW(L"button",L"Graph ein",WS_VISIBLE | WS_CHILD | ES_CENTER ,110,5,100,23, hwnd1, (HMENU) 2,0,0);       
        Knopf[6]=CreateWindowW(L"button",L"Probe",WS_VISIBLE | WS_CHILD | ES_CENTER ,703,507,100,55, hwnd1, (HMENU) 2,0,0);
        Knopf[7]=CreateWindowW(L"button",L"Menü",WS_VISIBLE | WS_CHILD | ES_CENTER ,5,5,100,23, hwnd1, (HMENU) 2,0,0);
        Knopf[8]=CreateWindowW(L"button",L"_",WS_VISIBLE | WS_CHILD | BS_CENTER | ES_CENTER  ,777,5,23,23, hwnd1, (HMENU) 2,0,0);
//_________________________________________________________________________________________________________________________________________________________________________________
// Meastime-input/display Boxes
        iSet=0;     
        while(iSet<AmountOfDatapointBufferint)
            {
            MeastimeC[iSet]=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILD|WS_VISIBLE| ES_CENTER,204,(80+(iSet * 50)),100,30,hwnd1,(HMENU)0,GetModuleHandle(NULL),NULL);
            iSet=iSet+1;
            }                   
//_________________________________________________________________________________________________________________________________________________________________________________
// Samplerate input/display Boxes   
        iSet=0;
        while(iSet<AmountOfDatapointBufferint)
            {
            SamplerateC[iSet]=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILD|WS_VISIBLE| ES_CENTER,363,(80+(iSet * 50)),100,30,hwnd1,(HMENU)0,GetModuleHandle(NULL),NULL);
            iSet=iSet+1;
            }
//_________________________________________________________________________________________________________________________________________________________________________________
// Comport number-entering Box
        ComportNumber=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","3",WS_CHILD|WS_VISIBLE| ES_CENTER,60,520,70,30,hwnd1,(HMENU)0,GetModuleHandle(NULL),NULL);
//_________________________________________________________________________________________________________________________________________________________________________________
// Standard-Valus are inserted into the boxes
        iSet=0;
        while(iSet<AmountOfDatapointBufferint)
            {
            SetWindowText(SamplerateC[iSet],"2");
            SetWindowText(MeastimeC[iSet],"1000");
            myPosition[iSet]=0;
            iSet=iSet+1;
            }
//_________________________________________________________________________________________________________________________________________________________________________________
// Names are dedicated to some Boxes (for optical purpose only, handles do exist aside these)       
        // Frames
        SetWindowText(GruppenBox[0],"Kanal");SetWindowText(GruppenBox[1],"Messdauer (Std)");SetWindowText(GruppenBox[2],"Samples pro Std.");SetWindowText(GruppenBox[3],"Messwert (mV)");
        // Checkboxes
        SetWindowText(CheckBox[1],"Kanal 1");SetWindowText(CheckBox[2],"Kanal 2");SetWindowText(CheckBox[3],"Kanal 3");SetWindowText(CheckBox[4],"Kanal 4");SetWindowText(CheckBox[5],"Kanal 5");SetWindowText(CheckBox[6],"Kanal 6");SetWindowText(CheckBox[7],"Kanal 7");SetWindowText(CheckBox[8],"Kanal 8");
//_________________________________________________________________________________________________________________________________________________________________________________
// Disabling of certain elements

        // Buttons
        EnableWindow(Knopf[2], FALSE);EnableWindow(Knopf[3], FALSE);
        EnableWindow(Knopf[4], FALSE);EnableWindow(Knopf[6],TRUE);
        // Textboxes
        iSet=0;
        while(iSet<16)
            {
            EnableWindow(MeasvalueC[iSet], FALSE);
            iSet=iSet+1;
            }
        iSet=0;
        while(iSet<9)
            {
            iBuffer[iSet]=0;
            iSet=iSet+1;
            }
        iSet=0;
        while(iSet<8)
            {
            Newtonscale[iSet]="";
            countmeup[iSet]=0;
            iSet=iSet+1;
            }
//_________________________________________________________________________________________________________________________________________________________________________________
// clearing the memory and writing "0" entryis to certain arrays
        iSet=0;iGraph=0;
        while (iSet<55)
            {
            while(iGraph<8)
                {
                UArray[iSet][iGraph]=0;
                iGraph=iGraph+1;
                }
            iSet=iSet+1;
            }
        return (int) lParam;
        }
    break;
    case WM_DESTROY:     //removed the commands because their not part of my current problem
    break;
    case WM_CLOSE:  //removed the commands because their not part of my current problem 
    break;
    case WM_COMMAND:    //removed the commands because their too long to be displayed and do work propperly
    break;
    case WM_PAINT:      //removed the commands because their not part of my current problem
    break;
    case WM_TIMER:      //removed the commands because their not part of my current problem
    break;
    }
return DefWindowProc (hwnd1, msg, wParam, lParam); 

Thank you for your help!

PPS: you are allowed to insult me as bad coder, i know that this must look like a wild monkey hopped around my keyboard.

****This is what the debugger is able to do bevore he starts shouting at me(/my code).

Process 1B00 started Thread 171C started Loading CSR-Messung HB628.exe at 0000000000400000 Loading untitled at 0000000077460000 Loading untitled at 0000000077640000 Loading untitled at 0000000074CC0000 Loading untitled at 0000000074C60000 Loading untitled at 0000000074C50000 Loading untitled at 0000000076D80000 Unloading untitled Loading untitled at 0000000074E30000 Unloading untitled Loading untitled at 0000000076D80000 Unloading untitled Loading untitled at 0000000077360000 Unloading untitled Loading untitled at 0000000074E30000 Loading untitled at 0000000074FF0000 Loading untitled at 0000000076900000 Loading untitled at 00000000760A0000 Loading untitled at 0000000074E20000 Loading untitled at 0000000074D80000 Loading untitled at 0000000076320000 Loading untitled at 0000000076A00000 Loading untitled at 00000000768B0000 Loading untitled at 0000000075E90000 Loading untitled at 0000000074D20000 Loading untitled at 0000000074D10000 Loading untitled at 0000000010000000 Loading untitled at 0000000075C90000 Loading untitled at 0000000075F80000 Loading untitled at 0000000071760000 Loading untitled at 0000000005F90000 Loading untitled at 0000000073F70000 Loading untitled at 0000000071350000 ODS:

%s------------------------------------------------

--- Themida Professional ---

--- (c)2012 Oreans Technologies ---


Thread 38C started Thread 1E54 started Thread 1EF4 started Thread 14AC started Thread 1D6C started Thread 15D4 started Thread 16C0 started Thread 1698 started Thread 1AE4 started Thread 1EC8 started Thread 1734 started Thread 1B7C started Thread 1FB0 started Thread 1840 started Thread 1718 started Thread 1570 started Thread 1F54 started Thread 1910 started Thread 1434 started Thread B8C started Thread E30 started Thread 1F24 started Thread 19A4 started Thread 1B40 started Thread 1E54 ended with 0 Thread 1EF4 ended with 0 Thread 15D4 ended with 0 Thread 38C ended with 0 Thread 16C0 ended with 0 Thread 1AE4 ended with 0 Thread 1EC8 ended with 0 Thread 1734 ended with 0 Thread 1B40 ended with 0 Thread 1570 ended with 0 Thread 1B7C ended with 0 Thread 1FB0 ended with 0 Thread 1F54 ended with 0 Thread E30 ended with 0 Thread 1718 ended with 0 Thread 1840 ended with 0 Thread 1910 ended with 0 Thread 1698 ended with 0 Thread 1D6C ended with 0 Thread 19A4 ended with 0 Thread 1F24 ended with 0 Thread 1434 ended with 0 Thread B8C ended with 0 Thread 14AC ended with 0 ODS:

* An Access Violation occurred in "C:\Users\dhin\Desktop\Ver11\CSR-Messung HB628.exe" .exr 000000000008BBB0 .cxr 000000000008B6C0 kb:

ODS: The instruction at 0000000074C94D62 tried to read from ODS: an invalid address, 0000000000000010

ODS: * enter .exr 000000000008BBB0 for the exception record ODS: * enter .cxr 000000000008B6C0 for the context ODS: * then kb to get the faulting stack

*Edit 1: corrected some spelling misstakes (am pretty bad in english lanquage/gramatic in general)

**Edit 2: added information about the IDE, asked additional question

****Edit 3: added ome stuff which may be usefull

Edit 4: I figured out that the invalid adress, the one which is causing the Privileged Instruction and later access violation, is inside the external lib i am using. Dont shoot me when i am wrong.It is looking somewhat like this:

00000010 20 20 20 20 20 20 20 20 31 32 33 31 33 39 39 30 12313990

UPDATE:

I have ripped everything to the bones, created a naked window with a single button, and still the wrror occured. then, i threw the hb628.lib out of the linker. THe result was a perfectly working debug/execution. Unfortunately this means that i have to find a way of communicating with the I/O cards driver all by myself. Jesus, I dont even know how to edit a .lib or a dll....

Thank you for your time and help!

Upvotes: 1

Views: 764

Answers (1)

Martijn Wijns
Martijn Wijns

Reputation: 499

If I paste your code into an editor line 75 is the UpdateWindow call. In that case it is a bad sign that hwnd1 is 0. The UpdateWindow call needs a valid window handle (ShowWindow as well by the way). You need to figure out why the CreateWindowW call is failing. You can retrieve the error with GetLastError(), see:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679(v=vs.85).aspx

the return value section.

Make the code using hwnd1 conditional such that it only uses hwnd1 if it is valid, you can retrieve the error in the case where hwnd1 is 0.

Upvotes: 1

Related Questions