Solved

export in DLL

Posted on 1998-11-26
3
252 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 120
Macro to save highlighted rows as a separate file 5 43
viewing source code from eclipse 13 104
abstract class with all non abstract mentods 6 76
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli‚Ķ
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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