Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

question on riched20.dll vs. riched20.lib?

213 views
Skip to first unread message

rayzhao

unread,
Apr 10, 2003, 9:22:18 AM4/10/03
to
Hi All,

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

Igor Tandetnik

unread,
Apr 11, 2003, 1:54:28 PM4/11/03
to
DllMain of riched20.dll registers RICHEDIT_CLASS with Windows (see
RegisterClass) and contains the control's window proc, but it does not
export any funcitons that you may call directly. CreateWindow requires
the window class to be registered, otherwise it fails.

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,
>
>

rayzhao

unread,
Apr 12, 2003, 7:16:38 AM4/12/03
to
Yes, you are right.
I added a line
CreateTextServices(NULL,NULL,NULL);
a function inside riched20.dll, then my window can be created without problem.

Thank you Igor,


zhifang

0 new messages