?
Solved

export in DLL

Posted on 1998-11-26
3
Medium Priority
?
257 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
[X]
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
3 Comments
 

Author Comment

by:tangkh
ID: 1325356
Edited text of question
0
 
LVL 86

Accepted Solution

by:
jkr earned 150 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

741 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