alexBrasil
asked on
how i create a DLL, correctly?
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".
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".
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...
// 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...
Oh, and jhance is of course right, the names are case sensitive also...
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.
#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.
venkaiah,
this already has been covered...
this already has been covered...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Am I the only one who can see that this question has already been answer in full?
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...
Without a case-correct spelling, the rundll call won't work, but neither would it with a C++ mangled name as the export...
It sure would be nice if alexBrasil would come back and attend to his question.....
Well, this really would be helpful, indeed...
"Myfunction"
In the function you specify:
"MyFunction"
DLL calls ARE CASE SENSITIVE!!