Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
Unhandled exception at 0x00a11e5e in muj.exe: 0xC0000005: Access violation reading location 0x00000000.

Problem with the above specified runtime error.

Please help me out.

Here is the code which generates such an exception

BSTR MethodName = SysAllocString(L"Create");
    BSTR ClassName = SysAllocString(L"Win32_Process");

    IWbemClassObject* pClass = NULL;
    hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);

    IWbemClassObject* pInParamsDefinition = NULL;
    hres = pClass->GetMethod(MethodName, 0, 
        &pInParamsDefinition, NULL);

    IWbemClassObject* pClassInstance = NULL;
    hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);

    // Create the values for the in parameters
	 VARIANT varComman;
    varComman.vt = VT_BSTR;
	varComman.bstrVal = L"CScript E:/vinay.vbs";

    VARIANT varCommand;
    varCommand.vt = VT_BSTR;
	varCommand.bstrVal = L"CScript E:/mof.vbs";


    // Store the value for the in parameters
	 hres = pClassInstance->Put(L"CommandLine", 0,
        &varComman, 0);
    wprintf(L"The command is: %s\n", V_BSTR(&varComman));

    hres = pClassInstance->Put(L"CommandLine", 0,
        &varCommand, 0);
    wprintf(L"The command is: %s\n", V_BSTR(&varCommand));

	 IWbemClassObject* pOutParam = NULL;
    hres = pSvc->ExecMethod(ClassName, MethodName, 0,
    NULL, pClassInstance, &pOutParam, NULL);
     
	IWbemClassObject* pOutParams = NULL;
    //hres = pSvc->ExecMethod(ClassName, MethodName, 0,
    //NULL, pClassInstance, &pOutParams, NULL);

    // Execute Method
   

    if (FAILED(hres))
    {
        cout << "Could not execute method. Error code = 0x" 
             << hex << hres << endl;
        VariantClear(&varCommand);
        SysFreeString(ClassName);
        SysFreeString(MethodName);
        pClass->Release();
        pInParamsDefinition->Release();
        pOutParams->Release();
        pSvc->Release();
        pLoc->Release();     
        CoUninitialize();
        return 1;               // Program has failed.
    }

    // To see what the method returned,
    // use the following code.  The return value will
    // be in &varReturnValue
    VARIANT varReturnValue;
    hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0, 
        &varReturnValue, NULL, 0);
Posted
Updated 18-May-11 21:32pm
v4
Comments
HimanshuJoshi 18-May-11 19:46pm    
Great, so now you have posted the exception, post the source code which creates the exception. Just post the relevant parts not the whole source code.
Sergey Alexandrovich Kryukov 18-May-11 19:53pm    
It can be anything at all! I'm just curious how did you imagine anyone would answer.
--SA
Dalek Dave 19-May-11 3:32am    
Edited for Grammar and Readability.

1 solution

Assuming you have the source code, and a .map or .pdb file, you can look up what the address 0x00a11e5e corresponds to. There is more information about this in the Microsoft knowledge base article How to identify where a failure is occurring in your code by using the address in the error message that you receive[^].

Otherwise I recommend a debug build and a debug session.

Edit after code was submitted: You are not checking the HRESULTS anywhere. Why is that? The error message says you are dereferencing a null pointer somewhere. Check the return values.
 
Share this answer
 
v2
Comments
Dalek Dave 19-May-11 3:32am    
Good Answer.
RaviRanjanKr 19-May-11 3:51am    
Nice Answer, My 5 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900