Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

export in DLL

Posted on 1998-11-26
3
Medium Priority
?
258 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

609 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