Jon Weinraub
Jon Weinraub

Reputation: 394

"HANDLE" is incompatible with parameter of type "HINSTANCE"

I had to update some strings since a few things had changed over the years but now it won't compile. This was originally done in VS2010. It was coded in Win32 API in C. Now I am using 2012 and it threw these errors:

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"

And this is the edited program:

// 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;
}

Upvotes: 0

Views: 2442

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283694

The code was written with STRICT off, apparently. This is like disabling all compiler warnings; well-written code will work, but the tools can't help you find errors. So I recommend leaving STRICT turned on in your project.

To eliminate the issue in the code you show, change the type of variable hModule from HANDLE to HINSTANCE. Evidently hModule had type HANDLE because the DllMain parameter it came from was using HANDLE, but that's wrong too. Use the correct signature shown on MSDN.

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

It sounds like there's a problem with the signature of DialogProc also, but you haven't shown us its definition. Perhaps you need to change its return type to INT_PTR, to match the documentation Also, do yourself a favor and use a different function name. As the doc says:

DialogProc is a placeholder for the application-defined function name.

You shouldn't need a cast on the LPARAM argument either.

Upvotes: 3

Related Questions