Microsoft 开发人员网络 > 论坛主页 > Visual C++ General > SendMessage and error 0xC0000005
提出问题提出问题
 

已答复SendMessage and error 0xC0000005

  • 2009年11月6日 22:47Narcyssus 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     包含代码
    i have a problem at
    case IDC_LBPS:
         {
          switch (HIWORD(wParam)) 
          { 
           case LBN_SELCHANGE:
           {
    	  	char bName[256];
           
    	    SendMessage(LBPS,LB_GETTEXT,SendMessage(LBPS,LB_GETCURSEL,0,0L),(LPARAM)bName);
    	    SendMessage(TN,WM_SETTEXT,0,(LPARAM)bName);
    		ReadPwrScheme(SendMessage(LBPS,LB_GETCURSEL,0,0L),&pp);
    		SendMessage(TV,WM_SETTEXT,0,(LPARAM)(LPCWSTR)pp.user.VideoTimeoutAc);
    		        
    	 	break; 
           }
    
    	   break;
          }
    
    	  break;
         }
    
    program compiles, but
    When i'mtrying to sendmessage to edit control with the powerpolicy.user.VideoTimeoutAc i have an error  "0x7e38c1f9" "MyKursTst.exe": 0xC0000005: "0x00000384".

    help please

    P.S. Sorry for my english.

答案

  • 2009年11月7日 19:33Nikita Leontiev 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    You need to convert pp.user.VideoTimeoutA to string.

    Do something like this:
    char *sTemp = new char[256];
    itoa(pp.user.VideoTimeoutAc, sTemp, 10);
    SendMessage(TV, WM_SETTEXT, 0, (LPARAM)(LPSTR)sTemp);
    delete[] sTemp;
    • 已标记为答案Narcyssus 2009年11月7日 20:39
    •  

全部回复

  • 2009年11月6日 23:05Nikita Leontiev 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     包含代码
    pp.user.VideoTimeoutAc what is it?

    You got access violation trying to retrieve it.
  • 2009年11月6日 23:12Narcyssus 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     包含代码
    POWER_POLICY pp;
    
    pp is global variable, and .user.VideoTimeoutAc one of its parametres
  • 2009年11月7日 0:01Nikita Leontiev 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    What function are you using to fill the POWER_POLICY struct? Check this code.
    Place breakpoint on SendMessage and look for VideoTimeoutAc value.

    Also, you cannot use VideoTimeoutAc as WM_SETTEXT message param, because it is ULONG. Need to convert to string.
    lParam should be pointer to a null-terminated string.
  • 2009年11月7日 0:02Sheng Jiang 蒋晟MVP用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Did you allocate memory for both .user and user.VideoTimeoutAc? Is the memory for VideoTimeoutAc large enough to hold the returning string?

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
  • 2009年11月7日 0:19Narcyssus 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    to fill POWER_POLICY struct i call ReadPwrScheme function.

    i think that "(LPCWSTR)" before argument convert argument, or I am not right?
  • 2009年11月7日 0:20Narcyssus 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    i just disclose variable of POWER_POLICY type...
  • 2009年11月7日 11:29Narcyssus 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    are there any other ways to realize a conclution of VideoTimeoutAc to edit control?
  • 2009年11月7日 19:33Nikita Leontiev 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    You need to convert pp.user.VideoTimeoutA to string.

    Do something like this:
    char *sTemp = new char[256];
    itoa(pp.user.VideoTimeoutAc, sTemp, 10);
    SendMessage(TV, WM_SETTEXT, 0, (LPARAM)(LPSTR)sTemp);
    delete[] sTemp;
    • 已标记为答案Narcyssus 2009年11月7日 20:39
    •  
  • 2009年11月7日 20:39Narcyssus 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Thx,  Nikita L, you helped mr very much.
    it's really works...