CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Dec 2008
    Posts
    19

    Help Needed Using DLL

    I have created a dll that has only one function in it and then i use that dll in a new project but the code is unable to locate the function in the dll

    MouseHandle Dll

    MouseHandle.h
    #ifndef _MOUSE_HANDLE_H_
    #define _MOUSE_HANDLE_H_
    #include <windows.h>
    #include <stdio.h>

    extern "C" __declspec(dllexport) LRESULT CALLBACK MyMouseProc(int,WPARAM,LPARAM);

    #endif

    MouseHandle.cpp
    #include "MouseHandle.h"


    extern "C" __declspec(dllexport)
    LRESULT CALLBACK MyMouseProc(int nCode,WPARAM wParam,LPARAM lParam) {
    MessageBox(NULL,L"SUCCESS",L"ERROR",MB_ICONEXCLAMATION | MB_OK);
    return 0;
    }

    Then i use this dll in my test project which doesn't works

    #include <windows.h>
    #include <stdio.h>

    static HINSTANCE hinstDLL;
    static HHOOK hhookSysMsg;


    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow){
    HOOKPROC hkprcSysMsg;
    hinstDLL = LoadLibrary(L"MouseHandle.dll");
    if(hinstDLL == NULL)
    errormessage();

    hkprcSysMsg = NULL;
    GetProcAddress(hinstDLL, L"MyMouseProc");
    if(hkprcSysMsg == NULL)
    errormessage();
    return 0;
    }

    The program compiles well but on debuggin gives the error "The Specified Procedure cannot be found"
    The Program is unable to find the procedure "MyMouseProc" in the dll

    Have I done any error in making the dll ?

  2. #2
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: Help Needed Using DLL

    GetProcAddress(hinstDLL, L"MyMouseProc");

    You aren't assigning anything this. You need assign the function pointer.

    Code:
    hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, L"MyMouseProc");
    You just need to cast the GetProcAddress to whatever your function prototype is, you can define your own function pointers for this.
    What you were doing is just loading the procedure but it wasn't stored anywhere. Now you call hkprcSysMsg like you would the DLL function itself.
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Help Needed Using DLL

    Quote Originally Posted by varundua View Post
    Code:
    GetProcAddress(hinstDLL, L"MyMouseProc");
    Have I done any error in making the dll ?
    How did you even compile that? GetProcAddress doesn't take pointer to a wide string.
    To Notsosuperhero: although you are right, the cast you suggested won't help to fix OP's error "The Specified Procedure cannot be found".
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #4
    Join Date
    Aug 2008
    Location
    C:\Windows\System32
    Posts
    47

    Re: Help Needed Using DLL

    either it's this
    Code:
    (HOOKPROC)
    or hes using multi-byte character set.

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Help Needed Using DLL

    Quote Originally Posted by Cha0sBG View Post
    either it's this
    Code:
    (HOOKPROC)
    or hes using multi-byte character set.
    Not sure what do you mean.
    1. The (HOOKPROC) cast has nothing to do with the error.
    2. Regardless of whether UNICODE was used or not, the GetProcAddress() function is only available in one flavor (unlike many other API function); it doesn’t take a wide string, and the prefix L in front of the text literal explicitly means: wide.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  6. #6
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Help Needed Using DLL

    It does take a wide string under CE.

    gg

  7. #7
    Join Date
    Dec 2008
    Posts
    29

    Re: Help Needed Using DLL

    use Depends.exe from "Microsoft Visual Studio 8\Common7\Tools\Bin" and check you dll to see if the name of your exported function is the same...

  8. #8
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Help Needed Using DLL

    Quote Originally Posted by Codeplug View Post
    It does take a wide string under CE.
    You are correct. I didn't know that. In my defence, if there would be any mention of WinCE - I would stay out of this thread.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Help Needed Using DLL

    Quote Originally Posted by varundua
    Code:
    extern "C" __declspec(dllexport) LRESULT CALLBACK MyMouseProc(int,WPARAM,LPARAM);
    . . .
    The program compiles well but on debuggin gives the error "The Specified Procedure cannot be found"
    The Program is unable to find the procedure "MyMouseProc" in the dll
    With this declaration the exported name must be _MyMouseProc@12.

    Besides, I cannot see any reason to resolve dll entry explicitly. Why don't you go with .lib?
    Best regards,
    Igor

  10. #10
    Join Date
    Dec 2008
    Posts
    19

    Re: Help Needed Using DLL

    Quote Originally Posted by Notsosuperhero View Post
    GetProcAddress(hinstDLL, L"MyMouseProc");

    You aren't assigning anything this. You need assign the function pointer.

    Code:
    hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, L"MyMouseProc");
    You just need to cast the GetProcAddress to whatever your function prototype is, you can define your own function pointers for this.
    What you were doing is just loading the procedure but it wasn't stored anywhere. Now you call hkprcSysMsg like you would the DLL function itself.
    I have tried this but doesn't helped , so i removed it but of no use.

  11. #11
    Join Date
    Dec 2008
    Posts
    19

    Re: Help Needed Using DLL

    I have made a slight change but it doesn't help
    Code:
    hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, TEXT("_MyMouseProc@12"));
    if(hkprcSysMsg == NULL)
    	errormessage();

  12. #12
    Join Date
    Dec 2008
    Posts
    19

    Re: Help Needed Using DLL

    Quote Originally Posted by Igor Vartanov View Post
    With this declaration the exported name must be _MyMouseProc@12.

    Besides, I cannot see any reason to resolve dll entry explicitly. Why don't you go with .lib?

    _MyMouseProc@12 doesn't works either. I am using the dynamic linking since i have to create a System Wide Mouse Hook to check mouse clicks on desktop.

  13. #13
    Join Date
    Dec 2008
    Posts
    19

    Re: Help Needed Using DLL

    Quote Originally Posted by codecX View Post
    use Depends.exe from "Microsoft Visual Studio 8\Common7\Tools\Bin" and check you dll to see if the name of your exported function is the same...
    I used the tool it showed the function name as MyMouseProc. I still don't know what to do ??
    I am attaching the result of the depend.exe with this reply
    Attached Images Attached Images

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Help Needed Using DLL

    I used the tool it showed the function name as MyMouseProc. I still don't know what to do ??
    Say the truth is what to do. Either you miss (or cripple somehow) the CALLBACK modifier in your dll, or you use .def file that unmangles the exported name.

    See my sample, and you see all works fine so far.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Igor Vartanov; December 27th, 2008 at 10:49 AM.
    Best regards,
    Igor

  15. #15
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Help Needed Using DLL

    Quote Originally Posted by VladimirF View Post
    You are correct. I didn't know that. In my defence, if there would be any mention of WinCE - I would stay out of this thread.
    Vladimir, in your defence: there could not be a mention of WinCE, as there are no hooks in there.
    Last edited by Igor Vartanov; December 27th, 2008 at 10:51 AM.
    Best regards,
    Igor

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured