I meet a question on RichEdit control dll loading.
I created a project using application Wizard "Win32 Application"
option. In Frame window's client area, I created a RichEdit child
Window as,
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
...
case WM_CREATE:
LoadLibrary(TEXT("riched20.dll")); //runtime loading
GetClientRect(hWnd,&rc);
ghwndChild = CreateWindowEx(0,RICHEDIT_CLASS,_T("My Edit"),
WS_CHILD| WS_VISIBLE ,
0,0,0,0,
hWnd,
NULL,
hInst,
NULL);
err1=GetLastError();
assert(ghwndChild);
break;
..
}
This case works well.
Later, I removed line
LoadLibrary(TEXT("riched20.dll"))
and added "riched20.lib" in Project Settings (this file is located at:
.\Program Files\Microsoft SDK\Lib). Then CreateWindowEx(...) couldn't
function properly with ghwndChild is NULL, and GetLastError() returned
0x0000057f...richedit window can't created.
I get confused why "Load-Time Dynamic Linking" and "Run-Time Dynamic
Linking" behaves differently?
I use W2000, VC6 SP5 with SDK component installed.
Any answers are greatly appreciated!
zhifang
Now, when you remove explicit LoadLibrary and instead link to
riched20.lib, the linker sees that you do not actually call any function
in the DLL, and removes the dependency. The linker has no way to know
that somewhere in the program you use CreateWindow with a certain string
literal, and that for that to work the DLL needs to register something
under this string literal.
Since your EXE does not depend on riched20.dll, it is not loaded when
the EXE starts. Hence there's nobody to call RegisterClass, hence
CreateWindow fails.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
"rayzhao" <fangz...@yahoo.com> wrote in message
news:f4f1c9f6.03041...@posting.google.com...
> I meet a question on RichEdit control dll loading.
>
> I created a project using application Wizard "Win32 Application"
> option. In Frame window's client area, I created a RichEdit child
> Window as,
>
>
Thank you Igor,
zhifang