首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

求解下面的程序,如何强制转换?

2012-04-02 
求解下面的程序,怎么强制转换??C/C++ code/**Author:lichao*Date:01-14-2012*Description:Shutdown the co

求解下面的程序,怎么强制转换??

C/C++ code
/*  *Author:lichao  *Date:01-14-2012  *Description:Shutdown the computer remotely by mobile phone  */  #include<windows.h>  #include<stdio.h>  #define TITLE_LENGTH 256  #define EXIT_SUCCESS 0  #pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"")  BOOL CALLBACK lpMyEnumFunc(HWND hwnd, LPARAM lParam)  {      TCHAR szTitle[TITLE_LENGTH];      GetWindowTextW(hwnd,szTitle,TITLE_LENGTH);      if( 0==wcscmp(szTitle,TEXT("RemotingShutDownWorker")))      {          BOOL *pDetected=(BOOL *)lParam;          *pDetected=true;          return 0;      }      return 1;  }  int main()  {      BOOL bDetected=false;      BOOL *pDetected=&bDetected;      while(!bDetected)      {          EnumWindows(lpMyEnumFunc,(LPARAM)pDetected);          Sleep(5000);      }      //::MessageBoxW(NULL,TEXT("将要关机"),TEXT("远程关机"),MB_OK);      system("shutdown -s -t 20");      return EXIT_SUCCESS;  } --------------------Configuration: Cpp1 - Win32 Debug--------------------Compiling...Cpp1.cppD:\C++\测试\控制台\QQ远程关机\Cpp1.cpp(27) : error C2664: 'GetWindowTextW' : cannot convert parameter 2 from 'char [256]' to 'unsigned short *'        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style castD:\C++\测试\控制台\QQ远程关机\Cpp1.cpp(29) : error C2664: 'wcscmp' : cannot convert parameter 1 from 'char [256]' to 'const unsigned short *'        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast执行 cl.exe 时出错.


我是在控制台下运行的。。。提示需要对应类型,但是不知道该怎么强制转换类型。。。新手求解。。

[解决办法]
TCHAR szTitle[TITLE_LENGTH]; 
 
GetWindowText(hwnd,szTitle,TITLE_LENGTH); 
 
if( 0==_tcscmp(szTitle,TEXT("RemotingShutDownWorker"))) 
 
试试看
[解决办法]
如果你没有使用unicode 可以使用GetWindowTextA 函数一样的用法

热点排行
Bad Request.