I am using the following code in my WinMain function:
// Main message loop:
bool noQuit = true;
while (noQuit)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
noQuit = false;
}
else
{
DrawFrame();
}
}
This works fine when I compile with a 32-bit (Win32) platform. Under a 64-bit (x64) platform, the code compiles fine, but when I run it it crashes. With a debugger I found that it errors out with an access violation on the PeekMessage line. This only happens with 64-bit though, so I am wondering why this is? Is there something I am doing wrong or something that I should know about 64-bit that I am doing wrong?
I find it really strange because it does not always error out on the first step through that loop, sometimes it is the 2nd or even the 3rd time, but it always stops on the PeekMessage line with the same access violation.
Please comment if it would be helpful for me to post more code than just this part (I am 99% sure this is where there error is happening though).
Thanks!
EDIT Here is the constructor for the class that accesses the flash ocx....
CFlashDXPlayer::CFlashDXPlayer(HMODULE flashDLL, unsigned int width, unsigned int height)
{
m_userData = NULL;
m_flashInterface = NULL;
m_oleObject = NULL;
m_windowlessObject = NULL;
m_lastMouseX = 0;
m_lastMouseY = 0;
m_lastMouseButtons = 0;
m_dirtyFlag = false;
m_width = width;
m_height = height;
m_controlSite.Init(this);
m_controlSite.AddRef();
m_alphaBlackDC = NULL;
m_alphaBlackBitmap = NULL;
m_alphaBlackBuffer = NULL;
m_alphaWhiteDC = NULL;
m_alphaWhiteBitmap = NULL;
m_alphaWhiteBuffer = NULL;
HRESULT hr;
typedef HRESULT (__stdcall *DllGetClassObjectFunc)(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
if (flashDLL != NULL)
{
IClassFactory* aClassFactory = NULL;
DllGetClassObjectFunc aDllGetClassObjectFunc = (DllGetClassObjectFunc) GetProcAddress(flashDLL, "DllGetClassObject");
hr = aDllGetClassObjectFunc(CLSID_ShockwaveFlash, IID_IClassFactory, (void**)&aClassFactory);
if (FAILED(hr))
return;
aClassFactory->CreateInstance(NULL, IID_IOleObject, (void**)&m_oleObject);
aClassFactory->Release();
}
else
{
hr = CoCreateInstance(CLSID_ShockwaveFlash, NULL, CLSCTX_INPROC_SERVER, IID_IOleObject, (void**)&m_oleObject);
if (FAILED(hr))
return;
}
IOleClientSite* pClientSite = NULL;
hr = m_controlSite.QueryInterface(__uuidof(IOleClientSite), (void**)&pClientSite);
if (FAILED(hr))
return;
hr = m_oleObject->SetClientSite(pClientSite);
if (FAILED(hr))
return;
hr = m_oleObject->QueryInterface(__uuidof(IShockwaveFlash), (void**)&m_flashInterface);
if (FAILED(hr))
return;
m_flashInterface->DisableLocalSecurity();
m_flashInterface->PutEmbedMovie(FALSE);
m_flashInterface->PutAllowScriptAccess(L"always");
SetTransparencyMode(IFlashDXPlayer::TMODE_OPAQUE);
SetQuality(IFlashDXPlayer::QUALITY_HIGH);
hr = m_oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pClientSite, 0, NULL, NULL);
assert(SUCCEEDED(hr));
pClientSite->Release();
hr = m_oleObject->QueryInterface(__uuidof(IOleInPlaceObjectWindowless), (void**)&m_windowlessObject);
assert(SUCCEEDED(hr));
m_flashSink.Init(this);
m_flashSink.AddRef();
// Resize player
ResizePlayer(width, height);
}
and what is passed into this for flashDLL is m_FlashLibHandle where
m_flashLibHandle = LoadLibrary(L"Flash11e.ocx");