I am trying to make an activeX dll with VC9 and atl in order to create  
  
an image that will render an HTML page host by a Ibrowser control.  
  
Actually the code is running but it will do nothing... I don't know  
  
where the problem is. I have done a dll with an interface called  
  
Snapshot which have a method GetURL. By calling this method I want to  
  
specify an url to grab on the fly. I think that the problem occured  
  
when I try to call ::CreateWindow... Please help me to find what I  
  
have to change. Here is my actual code :  //////////////////////////////////////////////////////////////////
// CMain
//////////////////////////////////////////////////////////////////
class CMain :
public CWindowImpl <CMain>
{
friend CEventSink;public: CMain(LPTSTR uri, LPTSTR file, UINT delay, BOOL silent) : m_uDelay(delay),
m_dwCookie(0), m_URI(uri), m_fileName(file), m_bSilent(silent)/*,m_ax(NULL)*/ { } BEGIN_MSG_MAP(CMainWindow)
MESSAGE_HANDLER(WM_CREATE,  OnCreate)
MESSAGE_HANDLER(WM_SIZE,    OnSize)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_TIMER,   OnTimer)
END_MSG_MAP() LRESULT OnCreate  (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnSize    (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnDestroy (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnTimer   (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); BOOL SaveSnapshot(void);
BOOL DelayedSnapshot(void);private:
LPTSTR m_URI;
LPTSTR m_fileName;
BOOL   m_bSilent;
UINT   m_uDelay;
UINT   m_nIDEvent;
protected:
CComPtr<IUnknown> m_pWebBrowserUnk;
CComPtr<IWebBrowser2> m_pWebBrowser;
CComObject<CEventSink>* m_pEventSink;
HWND m_hwndWebBrowser;
DWORD m_dwCookie;
};
//////////////////////////////////////////////////////////////////
// Implementation of CMain Messages
//////////////////////////////////////////////////////////////////
LRESULT CMain::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HRESULT hr;
RECT old;
IUnknown * pUnk = NULL;
GetClientRect(&old); m_hwndWebBrowser = ::CreateWindow(_T(ATLAXWIN_CLASS), m_URI,
WS_CHILD|WS_DISABLED, old.top, old.left, old.right,
old.bottom, m_hWnd, NULL, ::GetModuleHandle(NULL), NULL);
// TODO: Quit if m_hwndWebBrowser is null. hr = AtlAxGetControl(m_hwndWebBrowser, &m_pWebBrowserUnk); if (FAILED(hr))
return 1; if (m_pWebBrowserUnk == NULL)
return 1; hr = m_pWebBrowserUnk->QueryInterface(IID_IWebBrowser2, (void**)&m_pWebBrowser); if (FAILED(hr))
return 1; // Set whether it should be silent
m_pWebBrowser->put_Silent(m_bSilent ? VARIANT_TRUE : VARIANT_FALSE); hr = CComObject<CEventSink>::CreateInstance(&m_pEventSink); if (FAILED(hr))
return 1; m_pEventSink->m_pMain = this; hr = AtlAdvise(m_pWebBrowserUnk, m_pEventSink->GetUnknown(),
DIID_DWebBrowserEvents2, &m_dwCookie); if (FAILED(hr))
return 1; return 0;
}static const GUID myGUID = { 0x445c10c2, 0xa6d4, 0x40a9, { 0x9c, 0x3f, 0x4e, 0x90, 0x42, 0x1d, 0x7e, 0x83 } };
static CComModule _Main;
int DllInit(_TCHAR* url,_TCHAR* out)
{
HRESULT hr = _Main.Init(NULL, ::GetModuleHandle(NULL), &myGUID); if (FAILED(hr))
return EXIT_FAILURE; bool test = AtlAxWinInit();
if (!test)
return EXIT_FAILURE;
_TCHAR* argUrl = url;
_TCHAR* argOut = out;
int ax;
int argHelp = 0;
int argSilent = 0; unsigned int argDelay = 0;
unsigned int argMinWidth = 800;
unsigned int argMaxWait = 90000; if (argUrl == NULL || argOut == NULL || argHelp) {
IECaptHelp();
return 1;
}
CMain MainWnd(argUrl, argOut, argDelay, argSilent); RECT rcMain = { 0, 0, argMinWidth, 600 };
MainWnd.Create(NULL, rcMain, _T("IECapt"), WS_POPUP); // TODO: decide what to do when max-wait and delay conflict.
if (argMaxWait != 0)
MainWnd.SetTimer(ID_TIMEOUTTIMER, argMaxWait); MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
_Main.Term();
return 0;
}

解决方案 »

  1.   

    ”Actually the code is running but it will do nothing... “
    楼主啊, 标题党啊, 调用没出错 功能不正常如果你要网页截屏参考
    http://www.codeproject.com/KB/IP/htmlimagecapture.aspx
    http://www.codeproject.com/KB/graphics/IECapture.aspx这么长的代码。。 在下无能为力
      

  2.   

    首先感谢您的回答。
    我再把问题阐述更清楚些,这个代码来源于IECapture,我现在的目的是将其制作成Dll,以方便
    其他语言写的程序调用。
    当我将其包装到DLL中之后,刚开始一切正常,但是当程序运行到
    CreateWindow时,返回0,从而导致运行失败,当然也就无法实现网页截屏的功能。我的疑问是,为什么这个程序被改写为DLL之后,就无法运行,如何才能解决这个问题。
    谢谢大家的帮助。