" HANDLE"与#34; HINSTANCE"类型的参数不兼容

时间:2014-10-20 13:34:39

标签: c winapi

我不得不更新一些字符串,因为这些年来发生了一些变化,但现在它不会编译。这最初是在VS2010中完成的。它在C语言的Win32 API中编码。现在我使用的是2012,它抛出了这些错误:

1   IntelliSense: argument of type "HANDLE" is incompatible with parameter of type "HINSTANCE"  
2   IntelliSense: argument of type "LRESULT (__stdcall *)(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)" is incompatible with parameter of type "DLGPROC"

这是编辑过的程序:

// NSIS stack structure 
typedef struct _stack_t 
{
    struct _stack_t *next;
    char text[256];
} stack_t;

stack_t **g_stacktop;


// Function prototypes
char *getvar(int varnum);
void setvar(int varnum, char *var);
int runDialogBox();
HBITMAP LoadPicture(UINT nID);
BOOL DrawPicture(HDC hDC, LPRECT lpRect);

// Global variables 
char szBuf[256]="";
char szError[4]="";
int nVarError;
int res = 0;
HINSTANCE g_hInstance;
HWND g_hwndParent;
int g_stringsize;
char *g_variables;


BOOL APIENTRY DllMain( HANDLE hModulePar, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
LRESULT CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{

    static HBRUSH hBrushStatic;


void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variables, stack_t     **stacktop)
{
    g_hwndParent=hwndParent;
    g_stringsize=string_size;
    g_variables=variables;
    res = runDialogBox();
    if ( res == 0 )
        setvar(INST_1,"NO" );
    else
    setvar(INST_1,"YES" );
}

int runDialogBox()  
{
    int result = FALSE;
    result = DialogBoxParam(hModule, MAKEINTRESOURCE(IDD_DIALOG), NULL, DialogProc, (LPARAM)    (NULL));    

    return result;
}

1 个答案:

答案 0 :(得分:3)

显然,代码是用STRICT写的。这就像禁用所有编译器警告一样;编写良好的代码可以使用,但这些工具无法帮助您找到错误。因此,我建议您在项目中启用STRICT

要消除您显示的代码中的问题,请将变量hModule的类型从HANDLE更改为HINSTANCE。显然,hModule类型为HANDLE,因为它来自的DllMain参数使用的是HANDLE,但这也是错误的。使用the correct signature shown on MSDN

BOOL WINAPI DllMain(
                      _In_  HINSTANCE hinstDLL,
                      _In_  DWORD fdwReason,
                      _In_  LPVOID lpvReserved
                   );

听起来DialogProc的签名也存在问题,但您还没有向我们展示其定义。也许您需要将其返回类型更改为INT_PTR,以匹配the documentation此外,请帮自己一个忙,并使用不同的函数名称。正如医生所说:

  

DialogProc 是应用程序定义的函数名称的占位符。

您也不需要在LPARAM参数上进行投射。

相关问题