我在 WinMain 函数中使用以下代码:
// 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();
}
}
当我使用 32 位 (Win32) 平台编译时,这可以正常工作。在 64 位 (x64) 平台下,代码编译得很好,但是当我运行它时它崩溃了。使用调试器,我发现它在 PeekMessage 行上出现访问冲突错误。这只发生在 64 位,所以我想知道为什么会这样?有什么我做错了,或者我应该知道我做错了什么关于 64 位的事情吗?
我觉得这很奇怪,因为它并不总是在通过该循环的第一步出错,有时是第二次甚至第三次,但它总是在 PeekMessage 行上停止,并具有相同的访问冲突。
请评论是否对我发布更多代码而不只是这部分有帮助(我 99% 确定这是发生错误的地方)。
谢谢!
编辑 这是访问 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);
}
为 flashDLL 传递的内容是 m_FlashLibHandle,其中
m_flashLibHandle = LoadLibrary(L"Flash11e.ocx");