Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

export in DLL

Posted on 1998-11-26
3
253 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
ID: 1325356
Edited text of question
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 1325357
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
ID: 1325358
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 108
ASCII Non-Printable characters/codes and their HTML equivalents 6 130
sum13 challenge 24 121
Annoying "thing" blocks my view 4 115
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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