Re: CreateWindowEx AtlAxWin fails with last error 1407
David Liebtag <DavidLiebtag@vermontel.net> wrote:
Are you sure? Is that code you copied from a working program?
No, I haven't actually tested it (yes, I'm lazy like that). I
reverse-engineered this code from _DialogSplitHelper::ParseInitData.
When I read atlwin.h's _DialogSplitHelper::ParseInitData, it looks to
me like nMsg must be ATL_WM_OCC_LOADFROMSTREAM.
Yes, you are right. nMsg does need to be ATL_WM_OCC_LOADFROMSTREAM,
otherwise ParseInitData would always return E_FAIL.
When I read atlhost.h's AtlAxWindowProc2's WM_CREATE clause that
creates the stream to pass to _DialogSplitHelper::ParseInitData, it
looks to me like nCreateSize should not include itself and so should
be sizeof(WORD) smaller than you show.
Yes, this does seem to be the case.
So, with these comments, change the code to
struct CreateData {
WORD nCreateSize;
WORD nMsg;
DWORD dwLen;
DWORD cchLicKey;
};
BSTR licKey = ...; // the license key you want to provide
DWORD cchLicKey = SysStringLen(licKey);
WORD size = sizeof(CreateData) + cchLicKey;
BYTE* buf = new BYTE[size];
CreateData* data = reinterpret_cast<CreateData*>(buf);
data.nCreateSize = size - sizeof(WORD);
data.nMsg = ATL_WM_OCC_LOADFROMSTREAM;
data.dwLen = 0;
data.cchLicKey = cchLicKey;
memcpy(buf + sizeof(CreateData), licKey, cchLicKey * sizeof(OLECHAR));
CreateWindow(CAxWindow2::GetWndClassName(), ..., buf);
delete[] buf;
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925