Reputation: 125275
I am making a dll file and at the same time trying to call this function automatically when my DLL is loaded. How can I do this? It is a Windows API main function that creates a window but I dont know how do it. My first idea is to put it into DllMain function but I am really sure if this will work and also what to fill in the variables "HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow"
Below is the function I am trying to call automatically when my dll is loaded and I expect it to open a Window. Thanks.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow);
Upvotes: 0
Views: 2139
Reputation: 36318
There are limitations on what you can do in a DllMain function:
Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components.
That rules out creating a window directly from DllMain. What you can do, however, is launch a thread from your DllMain, and that thread can create a window.
Upvotes: 4
Reputation: 595981
DLLs do have a WinMain()
function. DllMain()
or DllEntryPoint()
are what you are looking for. Windows itself calls them when the DLL is loaded and unloaded. You do not call them yourself, you implement them instead. As for creating a window, you call CreateWindow/Ex()
and related functions.
Upvotes: 2