Re: CreateWindowEx AtlAxWin fails with last error 1407
Why don't you just use CAxWindow::Create?
Several reasons:
1) Because I am trying to add support for ActiveX to a program which already
uses CreateWindoEx for adding other types of controls to dialogs.
2) Because the portion of the program that adds controls is written in C
rather than C++
3) Because the documentation states either method should work
4) Because the technique you suggest doesn't work any better.
I tried using a simple program I found elsewhere on the web. Both
techniques hit an exception trying to read from address 000000. I attached
the program below.
I assume I must be doing something incorrectly, but I can't figure out what.
Can you?
David Liebtag
#include <windows.h>
#pragma comment(lib, "atl.lib")
#include <atlbase.h>
#include <atldef.h>
#include <atlhost.h>
#include <atlwin.h>
#define APP "My Class"
#define IDC_MYCTL 35
LRESULT CALLBACK MyWindowProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,PSTR sxCommand,int
iShow)
{
WNDCLASSEX myWindow;
myWindow.cbClsExtra = 0;
myWindow.cbSize = sizeof(myWindow);
myWindow.cbWndExtra = 0;
myWindow.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
myWindow.hCursor = LoadCursor(NULL,IDC_ARROW);
myWindow.hIcon = LoadIcon(NULL,IDI_APPLICATION);
myWindow.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
myWindow.hInstance = hInst;
myWindow.lpfnWndProc = MyWindowProc;
myWindow.lpszClassName = APP;
myWindow.lpszMenuName = NULL;
myWindow.style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&myWindow);
AtlAxWinInit();
HWND hWnd;
hWnd = CreateWindow(APP,"AtlAxWin Test",WS_OVERLAPPEDWINDOW,0,0,640,480,
NULL,NULL,hInst,NULL);
if(hWnd)
{
CAxWindow wnd;
RECT rect = {10,10,400,300};
// hWnd is the composite control handle
// rect is the size of ActiveX control in client coordinates
wnd.Create(hWnd, rect, _T("MSCAL.Calendar"), WS_CHILD| WS_VISIBLE,
0,IDC_MYCTL) ;
#if FALSE
HWND hWndX = CreateWindow("AtlAxWin71","http://www.google.com"
,WS_CHILD|WS_VISIBLE ,0,0,50,50 ,hWnd,NULL,hInst,NULL );
if(hWndX == 0)
{
char Message[1024] ;
sprintf(Message,"CreateWindow AtlAxWin failed. Last error:
%li",GetLastError()) ;
MessageBox(hWnd,Message,"AtlTest Message",MB_OK) ;
}
else
#endif
{
ShowWindow(hWnd, iShow);
UpdateWindow(hWnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
AtlAxWinTerm();
return 0 ;
}
LRESULT CALLBACK MyWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{
switch(msg)
{
case WM_CREATE:
{
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
return 0;
}
case WM_SIZE:
{
RECT clientRect;
GetClientRect(hWnd, &clientRect);
SetWindowPos(hWndX,HWND_TOP,0,0,clientRect.right,clientRect.bottom,SWP_NOZORDER);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}