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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:31:05+00:00 2026-06-14T21:31:05+00:00

I am trying to create a DLL in C++ and export a function. This

  • 0

I am trying to create a DLL in C++ and export a function.

This is my C++ code:

#include <Windows.h>

void DLLMain(){

}

__declspec(dllexport) void xMain(){
MessageBox(NULL,L"Test",L"Test",NULL);
}

This is my delphi code:

program prjTestDllMain;

Uses
  Windows;

Var
  xMainPrc:procedure;stdcall;
  handle : THandle;
begin
    handle := LoadLibrary('xdll.dll');
    if handle <> 0 then
    begin
        MessageBox(0,'DLL Loaded', 0, 0);
        @xMainPrc := GetProcAddress(handle, 'xMain');
        if @xMainPrc <> nil then
            MessageBox(0,'Function Loaded', 0, 0)
        else
          MessageBox(0,'Function Not Loaded', 0, 0);
        MessageBox(0,'Process End', 0, 0);
        FreeLibrary(handle);
    end else
      MessageBox(0,'DLL Not Loaded', 0, 0);
end.

I get a messagebox for “DLL Loaded” just fine. But I get “Function Not Loaded” afterwards. What am I doing wrong here?

  • 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-06-14T21:31:06+00:00Added an answer on June 14, 2026 at 9:31 pm

    You can export it as a C function (__cdecl), so that it has a nice name on the exports table.

    Name-decoration convention:
    Underscore character (_) is prefixed to names, except when exporting __cdecl functions that use C linkage.

    So basically, your function will have the name xMain in the exports table.

    extern "C" __declspec(dllexport) void xMain()
    

    And in the Delphi part, you just specify cdecl and call it normally:

    var
      xMainPrc: procedure; cdecl;
    

    For example:

    if @xMainPrc <> nil then
    begin
      MessageBox(0,'Function Loaded', 0, 0);
      xMainPrc;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create DLL out of my C# code, I found some
I'm trying to create a mixed mode dll with a few function exported for
I'm trying to create a DLL that exports a function called GetName. I'd like
I'm trying to create a Visual Studio project for code that contains DL_EXPORT(void) initlua(void);
I am trying to create a .NET DLL so I can use the cryptographic
I am trying to create a new library (.dll) for use in my SSIS
I’m trying to create a simple Win32 DLL. As interface between DLL and EXE
I am trying to create a C-style DLL interface that takes in an input
I am trying to create an offline registry in memory using the offreg.dll provided
In the below code, i am trying to reference an external .dll, which creates

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.