views:

371

answers:

3

I already spent whole day to trouble shoot this problem, but no luck yet. In my project, I set the Use of ATL property to Static Link to ATL on the General property page and set the Runtime Library property to Multi-threaded (/MT) on the Code Generation property page (C/C++ folder). However DependencyWalker still shows Atl71.dll dependency.

I googled and found this page http://www.eggheadcafe.com/forumarchives/vcatl/Mar2006/post26077463.asp with a solution of adding atlwin.h right after atlbase.h. This solution did help to reduce the dependency on atl71.dll. However it introduce a new problem, which is CreateWindow CAN NOT work correctly..

  // Creates the Web Browser control and navigates to the 
  // specified web page.
  HWND hWnd = ::CreateWindow("AtlAxWin", "http://www.microsoft.com", 
     WS_CHILD|WS_VISIBLE, 10, 10, 500, 300, hParent, NULL,
     ::GetModuleHandle(NULL), NULL);

The hwnd is NULL.

So the solution of adding atlwin.h can NOT be used, I wonder if anybody came across the similar static link problem before? How to resolve it?

Environment: VS 2003 .Net

Thanks!

A: 

I found a similar problem when upgrading from Visual Studio 6 to 2005. The fix was to include the version number in the window class name, so in my case it looked like this:

hwndControl = ::CreateWindow("AtlAxWin80", ...);

So with Visual Studio 2003, you might find that this:

hwndControl = ::CreateWindow("AtlAxWin71", ...);

works.

(On a much more basic level, are you calling AtlAxWinInit()?)

RichieHindle
I changed it to:#define ATLAXWIN_CLASS "AtlAxWin71" (def in atldef.h)hwnd = ::CreateWindow(_T(ATLAXWIN_CLASS), ...);The problem is still there. The GetLastError result is 0 (ERROR_SUCCESS). Any idea?
bionicoder
@bionicoder: Yow. Sorry, not a clue.
RichieHindle
A: 

BTW: It seems, removing "Multi-threaded (/MT)" - is redundant, this option relates to runtime but not ATL.

Please add following code(from msdn sample) to discover why hwnd is NULL

    LPVOID lpMsgBuf;
FormatMessage( 
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM | 
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    0, // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL 
);

// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, LError, MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
Dewfy
The return value of GetLastError() is 0 = ERROR_SUCCESS. So CreateWindow is successful. However the hwnd = 0x00000000
bionicoder
in that case check your window proc and make sure you aren't doing something goofy during WM_CREATE, WM_NCCREATE, etc. including not passing to DefWindowProc when you should.
Jewel S
Sorry, there are some errors in output after CreateWIndow execution. I just found it. Here it is: First-chance exception at 0x004a6ebc in DlgStatic.exe: 0xC0000005: Access violation reading location 0x00000000. Control creation failed for 'microsoft.com' Error code: 0x8007000e - Not enough storage is available to complete this operation. This error occurs after atlwin.h addition. Without it, it works ok except ATL71.DLL issue
bionicoder
A: 

an alternative to the CreateWindow call is AtlAxCreateControl. however, as far as i know if you use this you still bring in the dependency on atl71.dll.

if you want to host the web browser and can't take a dependency on atl71.dll you'll probably need to write the glue code yourself. it's not very difficult to basic hosting -- it should take less than the day you've spent on this. you also then have more control as well.

here's a sample: http://support.microsoft.com/default.aspx/kb/196339/en-us

you only need a small subset of this, primarily the logic in CWBExplorerBar::SetSite plus implementing a subset of the OLE interfaces, most of which can return E_NOTIMPL until you need that functionality.

~jewels

Jewel S