Question

I'm trying to construct a DLL for below code.

test.cpp

#include <windows.h>

bool _stdcall DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}

extern "C" _declspec(dllexport) bool _stdcall C_thread(LPSECURITY_ATTRIBUTES lpThreadAttributes,SIZE_T dwStackSize,LPTHREAD_START_ROUTINE lpStartAddress,LPVOID lpParameter,DWORD dwCreationFlags,LPDWORD lpThreadId)
{

    HANDLE hThread;
    DWORD threadID;
    hThread = CreateThread(lpThreadAttributes,dwStackSize,lpStartAddress,lpParameter,dwCreationFlags,lpThreadId);
    return hThread;

}

First I try to compile it by using below command in visual command prompt.

cl /Zi test.cpp kernel32.lib

but it's showing following error.

fatal error LNK1561: entry point must be defined

I need to solve this error by command prompt option.

Please help me to solve this.

Was it helpful?

Solution

The entry point type is wrong: BOOL is not the same as bool (see DllMain on MSDN). This is not Visual Basic but Visual C++.

You need to pass an additional option to the compiler to tell it to link as a DLL and not to link an executable image. A minimal example would be:

#include <windows.h>
BOOL WINAPI DllMain(HANDLE hInst, DWORD dwReason, LPVOID lpReserved)
{
    return TRUE;
}
BOOL WINAPI MyFunction(int value)
{
    return TRUE;
}

and compile with cl /nologo /W3 /Ox /Zi /MD /LD test.cpp to get a test.dll out. The /Zi gets you symbols in a .pdb file.

OTHER TIPS

Finally I found the answer for my question. Below simple command will help.

cl /Zi /LD test.cpp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top