Solved

how i create a DLL, correctly?

Posted on 2002-04-01
10
398 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
Independent Software Vendors: 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

718 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