question on riched20.dll vs. riched20.lib? 
Author Message
 question on riched20.dll vs. riched20.lib?

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;
..

Quote:
}

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



Mon, 26 Sep 2005 21:22:18 GMT  
 question on riched20.dll vs. riched20.lib?
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


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

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



Wed, 28 Sep 2005 01:54:28 GMT  
 question on riched20.dll vs. riched20.lib?
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  

Quote:
> 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.



Wed, 28 Sep 2005 19:16:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. RichEd20.dll and Bounds Checker

2. strange error about riched20.dll?

3. Is Rich Edit 3.0(Riched20.dll) compatible in window 95

4. Riched20.dl &, Riched32.dll

5. Bug in Riched20.dll??

6. Riched20.dll

7. Riched20.dll access violation under Windows 2000

8. distribution - riched20.dll

9. GPF in RichEd20.dll with drag and drop on Windows 2000

10. GPF in RichEd20.dll with Drag&drop on Windows 2000

11. RichEditView Printing Problem using RICHED20.dll!!!!

12. Rich Edit 2.0 (riched20.dll)

 

 
Powered by phpBB® Forum Software