读书人

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

发布时间: 2012-04-02 19:58:59 作者: rapoo

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

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 函数一样的用法

读书人网 >C语言

热点推荐