Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIB file cannot be created in a process making a DLL

Status
Not open for further replies.

atzsea

Programmer
Jun 1, 2005
49
0
0
JP
I'm a beginner in C++, learning making a DLL.

I prepared two files: beepdll.cpp and beepdll.def
Code:
// beepdll.cpp

#include <windows.h>

// Entry Point

BOOL WINAPI DllMain(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
    return TRUE;
}

// beep

void __stdcall beep(DWORD dwCounter)
{
    DWORD loop;

    for(loop=0; loop<dwCounter; loop++)
    {
        Beep(400, 100);
        Sleep(1000);
    }
}

Code:
; beep.def

LIBRARY   beepdll

EXPORTS
	beep	@3

I set a project named beepdll in Visual Studio 2005 C++ Win32.
At this time, I did Build(in Release).
beepdll.dll was created, but beepdll.lib was not, which should be created.
I cannot have configured out the reason.
 
I find it easier to export things using __declspec
Code:
void __declspec(dllexport) beep(DWORD dwCounter)
{
    DWORD loop;
    for(loop=0; loop<dwCounter; loop++)    {
        Beep(400, 100);
        Sleep(1000);
    }
}
And to simplify usage by clients,
add _BUILDING_MY_DLL to the C++ Preprocessor defs in your dll project, an NOT in the clients using the dll.
put your declaration in the header like this
Code:
#ifdef _BUILDING_MY_DLL
    #define LINKAGE __declspec(dllexport)
#else
    #define LINKAGE __declspec(dllimport)
#endif

void LINKAGE beep(DWORD dwCounter);
and the implmentation like
Code:
void beep(DWORD dwCounter){
    DWORD loop;
    for(loop=0; loop<dwCounter; loop++)    {
        Beep(400, 100);
        Sleep(1000);
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top