1

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");
M. Laing
  • 1,607
  • 11
  • 25
  • Use [dependency walker](http://www.dependencywalker.com/) to see if any of your DLL/Com Objects/OCXs are 32 bit and/or problematic... – JimR Feb 13 '12 at 19:37
  • Are you using DLL Injection to intercept the messages? If so, you may want to take a look at this article: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx – David Feb 13 '12 at 18:47
  • To be honest I'm not quite sure if I am using DLL Injection. It is quite possible... I'm trying to utilize a library [flash-to-directx](http://code.google.com/p/flash-to-directx/) and I'm not exactly sure what is going on. Here is the class that sets up the flash library (I'm guessing if it is using injection that it would be in here?).... sorry the code does not fit so I am adding it to my original post... – M. Laing Feb 13 '12 at 19:04
  • The part I don't quite understand is what GetProcAddress(flashDLL, "DllGetClassObject"); is doing. Is this returning a DLL that will be used... if so how does it know what DLL to use? I was assuming that since I pulled the flash ocx from the SysWOW64 directory that it would be 64-bit... if it is shouldn't the DLL be too? This is where I am just not sure how it works. – M. Laing Feb 13 '12 at 19:11
  • While I don't see any SetWindowsHookEx calls in there, Flash is probably loaded as a 32-bit DLL, and so GetProcAddress from a 64-bit exe could be part of what is causing problems... though you said it doesn't crash at that point. Does this help at all?: http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/15c780e3-d494-4c75-b69a-c100f3c350f6 – David Feb 13 '12 at 19:13
  • Yea I searched my entire solution and there are no SetWindowsHookEx calls, so I figured it probably has something to do with the flash library. The link you provided suggests to rebuild the library as a 64-bit library. I can't do that for this since I don't have the code for flash player... but I thought it was supposed to have a 64-bit version from things I've read before... I assumed it would be the ocx in the SysWOW64 directory because isn't that where they normally go? Is there anyway to check if it is a 64 bit DLL? Also is there anyway to make sure it is picking the 64 bit one? Thanks! – M. Laing Feb 13 '12 at 19:19
  • SysWow64 is actually the 32-bit version of the DLL. That might be the problem! WoW64 stands for "Windows on 64-bit Windows", and it contains all the 32-bit binary files required for compatibility, which run on top of the 64 bit Windows. See if there's another 64-bit OCX/DLL somewhere maybe. As far as how to instruct the browser to use a different version, I'm not sure. – David Feb 13 '12 at 19:25
  • There is one under System32 but I thought that it was the 32 bit version based on the 32 in System32... I tried it and it gives the same results.. hmm.. I'll do some looking around and see if there is indeed a 64-bit version that I don't have. I would be suprised though because flash works in my 64-bit IE browser. Thanks for the info about SysWow64... did not know that! – M. Laing Feb 13 '12 at 19:34
  • The one in system32 should be the 64-bit version, that is interesting :( – David Feb 13 '12 at 19:40
  • Yea the one in system32 is called "Flash64_11_1_102.ocx". So I guess the problem is not with that... I guess I'll have to keep looking and see if any other DLL's are being used that could be the problem. Thanks for the help so far! P.S. is it strange that the system32 version works when I compile under win32? Does that mean it actually is 32-bit or could it just happen to work with both? – M. Laing Feb 13 '12 at 19:44
  • Yeah, I actually wouldn't expect the 32-bit version of the exe to work with the 64-bit DLL. – David Feb 13 '12 at 20:06

0 Answers0