#include "CmnHdr.h" /* See Appendix A. */
#include <Windowsx.h>
#include <tchar.h>
#include "Resource.h"int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) { HWND hwnd = FindWindow(TEXT("#32770"), TEXT("Error Show"));
if (IsWindow(hwnd)) {
// An instance is already running, activate it and send it the new #
SendMessage(hwnd, ESM_POKECODEANDLOOKUP, _ttoi(pszCmdLine), 0);
} else {
::DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_ERRORSHOW),
NULL, Dlg_Proc,_ttoi(pszCmdLine));
}
return(0);
}C:\Documents and Settings\Administrator\桌面\01-ErrorShow\ErrorShow.cpp(125) : errorC2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned in
t,unsigned int,long)'
这是CD上的源码为何出现这种问题
#include <Windowsx.h>
#include <tchar.h>
#include "Resource.h"int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) { HWND hwnd = FindWindow(TEXT("#32770"), TEXT("Error Show"));
if (IsWindow(hwnd)) {
// An instance is already running, activate it and send it the new #
SendMessage(hwnd, ESM_POKECODEANDLOOKUP, _ttoi(pszCmdLine), 0);
} else {
::DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_ERRORSHOW),
NULL, Dlg_Proc,_ttoi(pszCmdLine));
}
return(0);
}C:\Documents and Settings\Administrator\桌面\01-ErrorShow\ErrorShow.cpp(125) : errorC2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned in
t,unsigned int,long)'
这是CD上的源码为何出现这种问题
INT_PTR CALLBACK DlgProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)错误提示中,你的定义里有两处不同于要求。
一是返回类型你返回的是long,参数要求int
二是调用约定不同。你使用的是默认约定,系统要求用__stdcall(也就是CALLBACK),这是最要注意的,因为虽然默认约定通常都是__stdcall,但万一设置被改了,不是__stdcall了,那你的程序就会错得莫名其妙。
INT ----32-bit signed integer.
INT_PTR -----Signed integral type for pointer precision. Use when casting a pointer to an integer to perform pointer arithmetic.
你用的是什么版本的SDK啊!?
DLGPROC的声明用的都是INT_PTR,如下:
typedef INT_PTR (CALLBACK* DLGPROC)(HWND, UINT, WPARAM, LPARAM);
怎么会不行?
就可以了,为什么呢请赐教
chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
chHANDLE_DLGMSG(hwnd, WM_COMMAND, Dlg_OnCommand); case ESM_POKECODEANDLOOKUP:
SetDlgItemInt(hwnd, IDC_ERRORCODE, (UINT) wParam, FALSE);
FORWARD_WM_COMMAND(hwnd, IDOK, GetDlgItem(hwnd, IDOK), BN_CLICKED,
PostMessage);
SetForegroundWindow(hwnd);
break;
} return(FALSE);
}
这是CD和书上的源码,我一点没动, redleaves(无心红叶)说定义的问题不会吧,我用的是vc6.0应该不会有问题吧
编译器死活都说 GWLP_HINSTANCE没有定义.
请问这个是为什么阿??
一。你输入有错,打错字是难免的,还有大小写问题。
二。头文件没有正确包含,很多API不是只包含windows.h就可以的。
三、环境变量没有定义好,这里的环境变量不是指操作系统的环境变量。是指编译系统所要求的宏。比如:WINNT,WIN32,_MSC_VER这一类的宏,很多API会对这些宏的定义有要求,尤其是关于Windows版本和IE版本的那几个宏。在MSDN里会有详细的说明,什么函数,类型,常量要在什么版本的IE,Windows下用。另外,GetWindowLongPtr是为了兼容64位OS加的新API,功能和GetWindowLong是一样的,在VC6里,肯定是没有的。VC6是98年出的。你可以用VS。NET或安一个新的SDK代替VC6里的。