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 6054991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:12:53+00:00 2026-05-23T08:12:53+00:00

I can compile DLLs properly using mingw and do the exports/imports stuff. What I

  • 0

I can compile DLLs properly using mingw and do the exports/imports stuff. What I am looking for is defining the dll onload function properly as you would in MS VC products. Google didn’t turn up anything. Anyone have any ideas or a link to a tutorial?

  • 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-23T08:12:54+00:00Added an answer on May 23, 2026 at 8:12 am

    Okay, so after some fiddling…it’s working. For anyone else that is having issues here it is. My issues weren’t related to compiling in instead of loading dynamically. It was a mash-up of a couple of tutorial/question/how-tos that got me to this point.

    dll.c

    
    #include <stdio.h>
    #include <windows.h>
    #include "dll.h"
    
    //extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD Reason, LPVOID LPV) {
    //This one was only necessary if you were using a C++ compiler
    
    BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
    
        switch (fdwReason)
        {
            case DLL_PROCESS_ATTACH:
                // Code to run when the DLL is loaded
            printf ("Load working...\n");
                break;
    
            case DLL_PROCESS_DETACH:
                // Code to run when the DLL is freed
            printf ("Unload working...\n");
                break;
    
            case DLL_THREAD_ATTACH:
                // Code to run when a thread is created during the DLL's lifetime
            printf ("ThreadLoad working...\n");
                break;
    
            case DLL_THREAD_DETACH:
                // Code to run when a thread ends normally.
            printf ("ThreadUnload working...\n");
                break;
        }
    
        return TRUE;
    } 
    
    EXPORT void hello(void) {
        printf ("Hello\n");
    }
    

    dll.h

    
    #ifndef DLL_H_
    #define DLL_H_
    
    #ifdef BUILD_DLL
    /* DLL export */
    #define EXPORT __declspec(dllexport)
    #else
    /* EXE import */
    #define EXPORT __declspec(dllimport)
    #endif
    
    EXPORT void hello(void);
    
    #endif /* DLL_H_ */
    

    hello.c

    
    #include <windows.h>
    #include <stdio.h>
    
    int main () {
    
        /*Typedef the hello function*/
        typedef void (*pfunc)();
    
        /*Windows handle*/
        HANDLE hdll;
    
        /*A pointer to a function*/
        pfunc hello;
    
        /*LoadLibrary*/
        hdll = LoadLibrary("message.dll");
    
        /*GetProcAddress*/
        hello = (pfunc)GetProcAddress(hdll, "hello");
    
        /*Call the function*/
        hello();
        return 0;
    }
    

    when compiled with

    gcc -c -DBUILD_DLL dll.c
    gcc -shared -o message.dll dll.o -Wl,--out-implib,libmessage.a
    gcc -c hello.c
    gcc -o hello.exe hello.o message.dll
    

    produces the expected output of

    Load working...
    Hello
    Unload working...
    

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

Sidebar

Related Questions

Can I user mono's AOT feature to natively pre-compile .NET DLLs (and or EXEs)
I recently discovered you can compile JScript into console apps using a built in
How can you compile the code using javac in a terminal by using google-collections
Using ef4 code first you can create and compile classes and dbcontext. What happens
I learned that Xcode can compile c code, that means can we write whole
Haxe has Apache httpd modules and can compile to PHP code. These are 2
After installing gcc and mpich library in my linux I can compile my codes
I have a multi-module project. I thought I can compile only a single module
How can I compile QVFB for embedded-linux-QT4.5 ? Thanks, Sunny.
How can I compile and run a python file (*.py extension)?

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.