• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 544
  • Last Modified:

Calling a dll

Hi all, i have a dll with code like this :

BOOL __declspec(dllexport)__stdcall instala_gap()
{
      hkb=SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc,hins,0);
      hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,0);

      return TRUE;
}

BOOL __declspec(dllexport) Desinstala()
{
      BOOL noatrapar = UnhookWindowsHookEx(hkb);
      return noatrapar;
}

BOOL CGmapcApp::InitInstance()
{
      AFX_MANAGE_STATE(AfxGetStaticModuleState());
      hins=AfxGetInstanceHandle();
      return TRUE;
}

int CGmapcApp::ExitInstance()
{
      return TRUE;
}

CGmapcApp::CGmapcApp()
{
      //TODO: add construction code here,
      //Place all significant initialization in InitInstance
}


/////////////////////////////////////////////////////////////////////////////
// The one and only CGmapcApp object

CGmapcApp theApp;

 
What I have to change to call it with RunDll32 with the Instala_gap as EntryPoint ?

Thanks and Regards.
0
SalvaThor
Asked:
SalvaThor
  • 4
  • 2
  • 2
  • +1
1 Solution
 
jkrCommented:
>>What I have to change to call it with RunDll32 with the Instala_gap as EntryPoint ?

Make the declaration read

void CALLBACK __decspec(dllexport)
  Instala_gap(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

and the implementation
void CALLBACK __decspec(dllexport)
  Instala_gap(HWND, HINSTANCE, LPSTR, int);
{
     hkb=SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc,hins,0);
     hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,0);
}

and that will work. See also http://support.microsoft.com/kb/164787/en-us ("INFO: Windows Rundll and Rundll32 Interface")
0
 
BeyondWuCommented:
I think you also should add the following .def file to your project if your source file is .cpp file, otherwise Rundll may can't find the corresponding function from your dll

LIBRARY      "yourdllname.DLL"

EXPORTS
      Instala_gap  PRIVATE
      Desinstala  PRIVATE
0
 
jkrCommented:
It'd probably be easier to use

extern "C"
void CALLBACK __decspec(dllexport)
  Instala_gap(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

than adding a .def file.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tushar_compCommented:


hi,

 create .def file
 as explaind by  "BeyondWu"
 thyen build the project
 
 else if u want entry point to  b  

 LIBRARY      "dll project name"

 EXPORTS
     Instala_gap  @1    
     Desinstala  @2


i think this will b enough for u evryrhing else is fine

if its useful
let me know

Tushar
0
 
SalvaThorAuthor Commented:
I did all the things that you send me but when I use the Rundll32 nothing happens do you know why ?? maybe i'm wrong
with the command :

RUNDLL32.EXE SMOCL32.DLL, Instala_gap

Thanks and regards
0
 
jkrCommented:
That should be

RUNDLL32.EXE SMOCL32.DLL,Instala_gap

No spaces, as described in the article I linked.
0
 
SalvaThorAuthor Commented:
Sorry but I'm making some wrong because anything happens
when I execute : "RUNDLL32.EXE SMOCL32.DLL,Instala_gap"

This is my code :

In my .def file :

LIBRARY      "socl32"
DESCRIPTION  'socl32 Windows Dynamic Link Library'

EXPORTS
    ; Explicit exports can go here
      Instala_gap
***************************************************************************
In my .h file :

LRESULT __declspec(dllexport)__stdcall CALLBACK CBTProc(
                  int nCode,
                  WPARAM wParam,
                  LPARAM lParam);

void CALLBACK __declspec(dllexport)
  Instala_gap(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
***************************************************************************
And in my .cpp file :
void CALLBACK __declspec(dllexport)
  instalasmocl(HWND, HINSTANCE, LPSTR, int)
{
      hkb=SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc,hins,0);
}

BOOL CSmocl32App::InitInstance()
{
      AFX_MANAGE_STATE(AfxGetStaticModuleState());
      hins=AfxGetInstanceHandle();
      return TRUE;
}

int CSmocl32App::ExitInstance()
{
      return TRUE;
}

CSmocl32App::CSmocl32App()
{
      // TODO: add construction code here,
      // Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSmocl32App object

CSmocl32App theApp;

****************************************************************************
And when I compile it this is the result :


warning C4518: '__declspec(dllexport ) ' : storage-class or type specifier(s) unexpected here; ignored
warning C4230: anachronism used : modifiers/qualifiers interspersed, qualifier ignored
warning C4518: '__declspec(dllexport ) ' : storage-class or type specifier(s) unexpected here; ignored
warning C4230: anachronism used : modifiers/qualifiers interspersed, qualifier ignored
Linking...
   Creating library Debug/Socl32.lib and object Debug/Socl32.exp

Socl32.dll - 0 error(s), 4 warning(s)

Thanks for your help.
0
 
BeyondWuCommented:
your Instala_gap has four parameters, HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow, you should pass them in your command line.

RUNDLL.EXE <dllname>,<entrypoint> <optional arguments>
RUNDLL32.EXE SMOCL32.DLL,Instala_gap 12345 54321 yourcmdline 1

12345 is your hwnd, you can fetch it with spy++
54321 is your hinst, for dll, it's normally 0x1000000, for exe, it's 0x400000
those 2 parameter seems difficult to get/set correctly for you, I recommend you to eliminate those unnecessary parameters.
yourcmdline is the string which you want to pass to your instala_gap function.
the nCmdShow could be one of the following number
#define SW_HIDE             0
#define SW_SHOWNORMAL       1
#define SW_NORMAL           1
#define SW_SHOWMINIMIZED    2
#define SW_SHOWMAXIMIZED    3
#define SW_MAXIMIZE         3
#define SW_SHOWNOACTIVATE   4
#define SW_SHOW             5
#define SW_MINIMIZE         6
#define SW_SHOWMINNOACTIVE  7
#define SW_SHOWNA           8
#define SW_RESTORE          9
#define SW_SHOWDEFAULT      10
#define SW_FORCEMINIMIZE    11
#define SW_MAX              11

Anyway, please remove all unnecessary parameters and try again.
0
 
jkrCommented:
Thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now