Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:59:30+00:00 2026-05-24T12:59:30+00:00

I have to use a simple function from a DLL; I am able to

  • 0

I have to use a simple function from a DLL; I am able to load the library but GetProcAddress returns NULL. I think I understood name mangling but maybe I’m doing something wrong. Thanks (Code follows, asap I’ll add other information required):

mydll.h

#ifdef MYDLL_EXPORTS
#define MYDLL_API extern "C" __declspec(dllexport)
#else
#define MYDLL_API extern "C" __declspec(dllimport)
#endif

MYDLL_API void testFunction(void);
MYDLL_API LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam);

mydll.cpp

#include "stdafx.h"
#include "mydll.h"

// This is an example of an exported function.
MYDLL_API void testFunction(void)
{
MessageBox(NULL, (LPCWSTR)L"Test", (LPCWSTR)L"Test", MB_OK);
}

MYDLL_API LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// processes the message
if(nCode >= 0)
{
    if(wParam != NULL && wParam == MK_RBUTTON)
    {
        MessageBox(NULL, (LPCWSTR)L"Captured mouse right button", (LPCWSTR)L"Test", MB_OK);
    }
}

// calls next hook in chain
return CallNextHookEx(NULL, nCode, wParam, lParam);
}

code from main.cpp

...
case WM_CREATE:
    {   
        // creates state for window
        stateClassPointer = new stateClass();
        // saves states pointer in a space reserved for user data
        SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) stateClassPointer);

        // now it will load DLL and set up hook procedure for mouse events

        // declares local variables
        HOOKPROC hkprcMouseProc;
        HINSTANCE hinstDLL; 
        HHOOK hhookMouseProc; 
        //FARPROC WINAPI test;
        // loads DLL
        if((hinstDLL = LoadLibrary(TEXT("C:\\Users\\Francesco\\Dropbox\\poli\\bi\\not\\pds\\sp\\wk5\\lsp5\\Debug\\mydll.dll"))) == NULL)
        {
            MessageBox(hWnd, (LPCWSTR)L"Error loading DLL", (LPCWSTR)L"Error", MB_OK | MB_ICONERROR);
            break;
        }
        // saves DLL handle in the state class
        stateClassPointer->setHInstance(hinstDLL);
        // sets up hook procedure for mouse events
        if((hkprcMouseProc = (HOOKPROC)GetProcAddress(hinstDLL, "mouseProc")) == NULL)
        {
            MessageBox(hWnd, (LPCWSTR)L"Error setting windows hook: GetProcAddress", (LPCWSTR)L"Error", MB_OK | MB_ICONERROR);
            break;
        }
        if((hhookMouseProc = SetWindowsHookEx(WH_MOUSE, hkprcMouseProc, hinstDLL, 0)) == NULL)
        {
            MessageBox(hWnd, (LPCWSTR)L"Error setting windows hook: SetWindowsHookEx", (LPCWSTR)L"Error", MB_OK | MB_ICONERROR);
            break;
        }
        // saves hook handle in the state class
        stateClassPointer->setHHook(hhookMouseProc);
        /*test = GetProcAddress(hinstDLL, "testFunction");
        test();*/
    }
    break;
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:59:31+00:00Added an answer on May 24, 2026 at 12:59 pm

    Yes, the MessageBox() call succeeded without errors. Move the GetLastError() call before it.

    The error is otherwise predictable, it couldn’t find “mouseProc”. The name will be mangled in the DLL, most probably “_mouseProc@12”. Use dumpbin.exe /exports on your DLL to be sure.

    Fwiw: you can make this code less painful by not dynamically loading the DLL but just linking its import library. The fact that the DLL will be injected into other processes doesn’t also mean you have to inject it in yours. All you need is the module handle so you can call SetWindowsHookEx(). Get that from the DllMain() entry point or by using GetModuleHandle().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple function that returns an NSString after decoding it. I use
I have a simple C# function I wish to use from VBA. For the
I have developed a simple library in Ruby and need to use this in
I'm trying to make a call to a DLL function (via GetProcAddress etc) from
I'd like a simple example of exporting a function from a C++ Windows DLL.
I have a simple function which tries to get a value from an Obout
I wanted to export a simple function from a base class that I use
i have something like: #!/usr/bin/perl use strict; use warnings; use CGI::Simple; use DBI; my
Question simple and quick: I have started to use Netbeans to write some code
My use case is very simple : I have a GUI application, and inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.