Add based on CDialog class dialog DLL project CMainDlg
//instantiate the dialog
CMainDlg * mainDlg;
MainDlg=new CMainDlg;
mainDlg - & gt; Create (IDD_DIALOG_Main); Here,//execution program crashes
MainDlg - & gt; ShowWindow (SW_SHOW);
Online reference in defining a macro function head, namely AFX_MANAGE_STATE (AfxGetStaticModuleState ());
But the macro definition and the DLL's DllMain () function conflict (a combination of online information inference)
Prompt error: fatal error LNK1169: find multiple symbols of the definition of one or more
Then I don't know how to do???
CodePudding user response:
DllMainThe DllMain function is an optional method of entry into a dynamic - link library (DLL). If The function is 2, it is called by The system when The processes and threads are initialized and terminated, or upon calls to The LoadLibrary and FreeLibrary functions provides.
DllMain is a placeholder for the library - defined the function name. The Earlier versions of the SDK documentation, informs DllEntryPoint as the entry point - the function name. You must specify the actual name You use when You build your DLL. For more information, see the documentation included with your development tools.
BOOL WINAPI DllMain (
HINSTANCE hinstDLL,//handle to the DLL module
DWORD fdwReason,//"reason for calling the function
LPVOID lpvReserved//reserved
);
The Parameters
HinstDLL
A handle to the DLL. The value is the base address of the DLL. The HINSTANCE of A DLL is the same as the HMODULE of the DLL, so hinstDLL can be 2 in subsequent calls to the GetModuleFileName function and other functions provides that require A module handle.
FdwReason
Specifies a flag indicating according the DLL entry point - the function is being called. This parameter can be one of the following values: Value a fancy
DLL_PROCESS_ATTACH are that the DLL is being the loaded into the virtual address space of the current process as a result of the process starting up or as a result of a call to LoadLibrary. DLLs can use this opportunity to initialize any instance data or to use the TlsAlloc function to the allocate a thread local storage (TLS) index.
DLL_THREAD_ATTACH are that the current process is creating a new thread. When this occurs, the system calls the entry point - the function of all DLLs currently attached to the process. The call is made in the context of the new thread. DLLs can use this opportunity to initialize a TLS slot for the thread. A thread calling the DLL entry - point function with DLL_PROCESS_ATTACH does not call the DLL entry - point function with DLL_THREAD_ATTACH.
Note that a DLL 's entry point - the function is called with this value only by threads created after the DLL is the loaded by the process. When a DLL is the loaded using LoadLibrary, existing threads do not call the entry point - the function of the newly the loaded DLL.
DLL_THREAD_DETACH are that a thread is exiting cleanly. If the DLL has stored a pointer to the allocated memory slot in a TLS, it USES this opportunity to free the memory. The system calls the entry point function of all - currently the loaded DLLs with this value. The call is made in the context of the exiting thread.
DLL_PROCESS_DETACH are that the DLL is being unloaded from the virtual address space of the calling process as a result of either a process exit or a call to FreeLibrary. The DLL can use this opportunity to call the TlsFree function to free any TLS indices allocated by using TlsAlloc and free any thread local data.
LpvReserved
Specifies further aspects of DLL initialization and cleanup.
If fdwReason is DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads and non - NULL for static loads.
If fdwReason is DLL_PROCESS_DETACH, lpvReserved is NULL If the DllMain has had been called by using FreeLibrary and non - NULL If DllMain has had called during the process termination.
The Return Values
When the system calls the DllMain function have the DLL_PROCESS_ATTACH the value, the function returns TRUE if it succeeds or FALSE if initialization fails. If the return value is FALSE When DllMain is called because the process USES the LoadLibrary function, LoadLibrary returns NULL. If the return value is FALSE When DllMain is called during the process initialization, the process terminates with an error. To get extended error information, call GetLastError.
When the system calls the DllMain function with any value other than DLL_PROCESS_ATTACH, the return value is ignored.
Few
During the initial process startup or after a call to LoadLibrary, the system scans the list of the loaded DLLs for the process. For each DLL that has not already had called with the DLL_PROCESS_ATTACH the value, the system calls the DLL 's entry - point function. This call is made in the context of the thread that under caused the process address space to change, to the as the primary thread of the process or the thread that called LoadLibrary.
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull