Solved

export in DLL

Posted on 1998-11-26
3
249 Views
Last Modified: 2013-11-20
I created a DLL file, has the export function as follow:

==========DLL.CPP==========
__declspec(dllexport) void ProcessMessage(void)
{
      AFX_MANAGE_STATE(AfxGetStaticModuleState());
      return;
}

==========APP.CPP==========
CMain::CMain()
{
  void *processMsg;

  HINSTANCE hDll = LoadLibrary("DLL.DLL");

  if (hDll == NULL)
  {
    AfxMessageBox("WARNING! Can't load DLL.DLL", MB_OK | MB_ICONSTOP, 0);
    _exit (0);
  }
 
  processMsg = (void*) GetProcAddress(hDll,"ProcessMessage");

  if (processMsg == NULL)
  {
    DWORD err = GetLastError();
    wsprintf((LPSTR)sztmp, "%s%d", "Error Code:", err);
    AfxMessageBox(sztmp, MB_OK | MB_ICONSTOP, 0);
    _exit(0);
  }
}

I can load the DLL without any problem. But I always got GetProcAddress wrong, with error code 126, i.e. module not found. What did I go wrong?
0
Comment
Question by:tangkh
3 Comments
 

Author Comment

by:tangkh
Comment Utility
Edited text of question
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
Simply declare the function as
extern "C" __declspec(dllexport) void ProcessMessage(void)
and list it in your .def file (if it isn't listed here using the same name as in the call to 'GetProcAddress()', some linkers will probably prepend an underscore - to check this and the actual export name, you can use 'QuickView' from the Explorer's context menu).
0
 

Expert Comment

by:dekoay
Comment Utility
Hi tangkh!

You need to attach  *.DEF file during your program compilatio so that the other program that used this DLL could identify the module. If u do not know the format, then just follow the format below and save it as *.def

LIBRARY <DLL name>
DESCRIPTION
EXPORTS  
              <function name to export> @1

Dekoay
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 137
method notes when mouse over in eclipse 5 68
wait notify demo infinite loop 3 80
FizzBuzz challenge 9 72
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now