Solved

how i create a DLL, correctly?

Posted on 2002-04-01
10
379 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
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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Accepted Solution

by:
jemax earned 70 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now