How to define entry point in C ++ / CLI DLL with command line argument / ENTRY

The cl.exe file has an option to define a custom DLL entry point with the / ENTRY command line attribute. Unfortunately it doesn't provide an example on how to use it.

http://msdn.microsoft.com/en-us/library/f9t8842e%28v=vs.100%29.aspx

I created a managed C ++ DLL with / CLR support and replaced the main function name with "Start":

int Start(int argc, char *argv[])
{
    return 0;
}

      

Then I try to compile this DLL from the command line using this BAT command:

"c:\Program Files\Microsoft Visual Studio 12.0\VC\bin\cl.exe" ^
    /clr /Fo /Z7 /D "NDEBUG" ^
    /ENTRY:Start ^
    "..\Links\Links.cpp"

      

Unfortunately I am getting this error:

LNK1561: Entry point must be defined

      

Question . What exactly should be passed to the / ENTRY argument?

Edit : As mentioned in Hans' comment below, the function used for the DLL entry point must have a different signature, so I corrected the above example. The function below is an example of the entry point for an EXE file, especially since it manipulated the type among its parameters.

int Start(array<String ^> ^ argc)
{
    return 0;
}

      

+3


source to share


2 answers


Pointing /ENTRY

to a managed assembly is a very bad idea because now all of the .NET Framework support code in the C ++ runtime library will fail. C ++ global object initializers won't be able to run either. And you can get memory leaks in worker threads because the C ++ runtime library is smart enough to do local thread initialization when needed, but since it doesn't accept thread detach events, it won't be able to clean up. On the other hand, C ++ / CLI assemblies always dynamically link to the runtime DLL, so at least this library DllMain

will receive thread notifications and resources used by the runtime itself will not be missed.

Just leave the entry point DllMainCRTStartup

provided by the library alone and provide a named function DllMain

that the library entry point will call.

There is a lot of documentation on MSDN regarding initialization code in C ++ / CLI managed assemblies:



One of the important things to remove is that the signature DllMain

(which again is not the actual entry point, it is called from the library provided entry point),

BOOL WINAPI DllMain(
  _In_  HINSTANCE hinstDLL,
  _In_  DWORD fdwReason,
  _In_  LPVOID lpvReserved
);

      

+2


source


Stupid to me. The / ENTRY option is an argument to link.exe, not cl.exe

By using the following BAT script, I can get my assembly to have a custom entry point. The only thing is that for some reason in this case, the linker requires you to set the project type directly using the / SUBSYSTEM option.



"c:\Program Files\Microsoft Visual Studio 12.0\VC\bin\link.exe" ^
    /DLL /ENTRY:Start ^
    /SUBSYSTEM:CONSOLE ^
    /WX ^
    /OUT:Links.dll ^
    "Links.obj"

      

0


source







All Articles