bops 1 Posting Whiz in Training

I have created a simple DLL in C that in which contains a function to implement a Low-Level Mouse Hook to Clip the Cursor to a window. I have done this because I feel the ClipCursor() API is inadequate. Anyway.. the DLL header file contains the following code..

#include <windows.h>

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else
# define DLLIMPORT __declspec (dllimport)
#endif


DLLIMPORT BOOL GlobalClipCursor( HWND hWnd );


#endif

The C Source code of the DLL contains this code..

#include "dll.h"
#include <stdio.h>
#include <stdlib.h>

HINSTANCE g_hInst;
HHOOK     g_hHook;
HWND      g_hWnd;

LRESULT CALLBACK LowLevelMouseProc( int nCode, WPARAM wParam, LPARAM lParam )
{
    if ( ! ( nCode < 0 ) )
    {
          PMSLLHOOKSTRUCT hsInfo;
          hsInfo = (PMSLLHOOKSTRUCT) lParam;
       
          if ( wParam == WM_MOUSEMOVE )
          {
               HWND hwnd; 
               POINT p;
               
               p = hsInfo->pt;
                             
               hwnd = WindowFromPoint( p );
               
               if ( hwnd == g_hWnd )
               {
                  RECT rc;
                  GetWindowRect( hwnd , &rc );
                  
                  LONG lHor , lVer;
                  
                  if ( p.x < rc.left ) {
                      lHor = rc.left;
                  }
                  if ( p.x > rc.right ) {
                      lHor = rc.right;
                  }
                  if ( p.y < rc.top ) {
                      lVer = rc.top;
                  }
                  if ( p.y > rc.bottom ) {
                      lVer = rc.bottom;
                  }
                 
                  SetCursorPos( lHor , lVer );
               }
               else
               {
                   
               }
                    
          } // END: MOUSEMOVE
          
          if ( wParam == WM_LBUTTONUP   || wParam == WM_RBUTTONUP  ||
               wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN ) 
          {               
               
               HWND hwnd = WindowFromPoint( hsInfo->pt );
               if ( hwnd != g_hWnd )
               {
                  return 1;
               }               
          }
    }   // END: nCode 
    return CallNextHookEx( g_hHook , nCode , wParam , lParam );
}

DLLIMPORT BOOL GlobalClipCursor( HWND hWnd )
{
   if ( hWnd != NULL )
   {        
      g_hWnd = hWnd;    
      g_hHook = SetWindowsHookEx( WH_MOUSE_LL , LowLevelMouseProc , g_hInst , 0 );
   }
   else
   {
      UnhookWindowsHookEx( g_hHook );
   }
}


BOOL APIENTRY DllMain (HINSTANCE hInst , DWORD reason , LPVOID reserved )
{
    g_hInst = hInst;
    
    return TRUE;
}

This compiles fine so I don't need help with the above. My query is, when I load the DLL using LoadLibrary and then user GetProcAddress and try to use the exported function I get the following message when trying to compile..

cannot convert `HWND__*' to `TCHAR*' in argument passing

This is triggered by 2 lines of code that both read the following (hwnd is a global HWND variable)..

GlobalClipCursor( hwnd );

but where I have (to release the cursor)

GlobalClipCursor( NULL );

I have no problems.

What is going on since I created the function in the DLL to take a HWND as a parameter but in my implementation it says that it cannot convert HWND* to TCHAR*?

Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.