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

x
?
Solved

how i create a DLL, correctly?

Posted on 2002-04-01
10
Medium Priority
?
410 Views
Last Modified: 2012-05-04
I want create a DLL, but i read a MSDN library and our examples don't run correctly.

I want "RUN :  RUNDLL32 MYDLL,Myfunction".


is Example wrong?

// DLL.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
__declspec(dllexport) BOOL WINAPI MyFunction (HWND hwnd, LPLONG lpIValue, LPSTR lpszValue)
{
     MessageBox(NULL,"Message 1 - Test my DLL. Myfunction","Test",MB_OK);
     return 0;
}

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved )
{
    MessageBox(NULL,"Message 2 - Test my DLL, dllmain.","Test",MB_OK);
     return TRUE;
}
------------------------------------------------

When i run this example, and RUN: "RUNDLL32 mydll.dll,myfunction", it show "Message 2", but don't show "Message 1 ". It show Error in DLL.dll "Missing entry:Myfunction".


0
Comment
Question by:alexBrasil
[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
10 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6910843
At first glance your problem is simple.  In the RUNDLL32 call you specify:

"Myfunction"

In the function you specify:

"MyFunction"

DLL calls ARE CASE SENSITIVE!!
0
 
LVL 86

Expert Comment

by:jkr
ID: 6910889
make it read

// DLL.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

extern "C" // <--!!
__declspec(dllexport) BOOL WINAPI MyFunction (HWND hwnd, LPLONG lpIValue, LPSTR lpszValue)
{
    MessageBox(NULL,"Message 1 - Test my DLL. Myfunction","Test",MB_OK);
    return 0;
}

BOOL APIENTRY DllMain( HANDLE hModule,
                      DWORD  ul_reason_for_call,
                      LPVOID lpReserved )
{
   MessageBox(NULL,"Message 2 - Test my DLL, dllmain.","Test",MB_OK);
    return TRUE;
}

And it should work - I assume you have a .cpp file, so this is necessary to turn off the C++ name mangling...
0
 
LVL 86

Expert Comment

by:jkr
ID: 6910891
Oh, and jhance is of course right, the names are case sensitive also...
0
Industry Leaders: 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!

 
LVL 2

Expert Comment

by:venkaiah
ID: 6912416
Try in this way

#include "stdafx.h"
extern "C" __declspec(dllexport) BOOL MyFunction (HWND hwnd, LPLONG lpIValue, LPSTR lpszValue)
{
    MessageBox(NULL,"Message 1 - Test my DLL. Myfunction","Test",MB_OK);
    return 0;
}

BOOL APIENTRY DllMain( HANDLE hModule,
                      DWORD  ul_reason_for_call,
                      LPVOID lpReserved )
{
   MessageBox(NULL,"Message 2 - Test my DLL, dllmain.","Test",MB_OK);
    return TRUE;
}
i think this will helps you.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6912875
venkaiah,

this already has been covered...
0
 
LVL 1

Accepted Solution

by:
jemax earned 210 total points
ID: 6914250
Hi,

sorry, guys, but as far as I know, using "__declspec(dllexport)" leaves func. name decoration on compiler own, so the exported name (visible from outside (using "Depends" utility from VS)) will be something like "_MyFunction@12". If you call rundll32 mydll.dll _MyFunction@12 you will see both messages. If you want to decorate the name by yourself, use .DEF file.


alexBrasil, run "Depends" from VS tools, open your dll, and check the actual name of your exported function.

Best regards,
jemax
0
 
LVL 32

Expert Comment

by:jhance
ID: 6914262
Am I the only one who can see that this question has already been answer in full?
0
 
LVL 86

Expert Comment

by:jkr
ID: 6914441
jhance: No, you are not :o)

Without a case-correct spelling, the rundll call won't work, but neither would it with a C++ mangled name as the export...
0
 
LVL 32

Expert Comment

by:jhance
ID: 6914449
It sure would be nice if alexBrasil would come back and attend to his question.....
0
 
LVL 86

Expert Comment

by:jkr
ID: 6914454
Well, this really would be helpful, indeed...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

636 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