0

ATL を使用して単純な DLL プロジェクトを作成します。コードは次のようになります。

class main_window : 
    public wtlext::LayeredWindow<ATL::CWindowImpl<main_window>, bool>,
    public CVWModule,
    public IPropertyObserver
{
// Construction
public:
    main_window();
    ~main_window();

    HWND Create(HWND hWndParent)
    {
        ATL::CWindowImpl<main_window>::Create(hWndParent, rcDefault, NULL,
            WS_POPUP | WS_VISIBLE,
            WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_LAYERED);

        return m_hWnd;
    };
}

文字は Unicode で、runtimelibrary は MDd です

例外的な原因: コード 0xC0000005 種類: アクセス違反 説明: スレッドは、適切なアクセス権がない仮想アドレスに対して読み取りまたは書き込みを試みました。exe 中の 0x76fe8dc9 处最可能性异常: 0xC0000005: 書き込み位置 0x00000014 時間発生访问冲突</p>

ご迷惑をおかけして申し訳ありませんが、ここに投稿するのは初めてです。
プロジェクトがWTLを使用していることに加えて、exeがCAPPMODULEを使用していることがわかりました。DLL メイン CPP の下。` //#include "stdafx.h" //#include "iconized.h" //#include "iconizedDlg.h"

// #define UNICODE
// #define _UNICODE 

CAppModule _Module;



HINSTANCE hDll_Instance;
HWND hWnd;


extern "C" BOOL WINAPI DllMain( HMODULE hModule,
    DWORD  ul_reason_for_call,
    LPVOID lpReserved
    )
{



    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        {

            hDll_Instance = (HINSTANCE)hModule;



            //ShowWindow();
        }
        break;
    case DLL_THREAD_ATTACH:
        {

        }

        break;
    case DLL_THREAD_DETACH:

        break;
    case DLL_PROCESS_DETACH:{

        ;
                            }
                            break;
    }
    return TRUE;
}

 int WINAPI Iconized_tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
 {
    //AtlAxWinInit();
    Gdiplus::GdiplusStartupInput gdiplusStartupInput; 
    ULONG_PTR gdiplusToken; 
    int nRet = -1;


    // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
    ::DefWindowProc(NULL, 0, 0, 0L);

    // create VW module window as soon as we can
    iconized::main_window *pMainWnd = new iconized::main_window;
    assert(pMainWnd != 0);

    // Init module (ATL magic starts here)
    HRESULT  hRes = _Module.Init(NULL, hInstance);
    ATLASSERT(SUCCEEDED(hRes));

    AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);  // add flags to support other controls

    // Init GDI+
    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    // create main window
    if(pMainWnd->Create(0) == NULL)
    {
    ATLTRACE(_T("Main window creation failed!\n"));
    return 0;
    }

    pMainWnd->ShowWindow(nCmdShow);

    // Run main message loop
    CMessageLoop theLoop;
    _Module.AddMessageLoop(&theLoop);

    nRet = theLoop.Run();

    _Module.RemoveMessageLoop();

    // main window must be destroued before GDI+ is shutdown 
    // in order to release its resources properly
    pMainWnd->Destroy();

    // Finalize GDI+
    Gdiplus::GdiplusShutdown(gdiplusToken);

    _Module.Term();

    delete pMainWnd;

//#ifdef USE_MEMTRACK
//    std::stringstream s;
//    MemTrack::TrackDumpBlocks(s);
//    ::MessageBox(0, s.str().c_str(), "Memblocks", MB_OK);
//#endif

     return 0;
 }

`

4

1 に答える 1

0

この問題は解決されました。理由は、No call to InitializeCriticalSection(...); です。なぜなら、loadlibrary(*.dll) を使用したため、グローバル変数 (_AtlWinModule、_AtlBaseModule、_AtlComModule は後で ATL コンポーネントによって使用されます) が初期化されていません。 . したがって、この状況では、_CRT_INIT を DLLMain に追加することで、アクセス違反を克服できます。crt_INIT 関数は、関連するグローバル変数を初期化するのに役立ちます。お気に入り :

DLLMain增加_CRT_INIT (ul_reason_for_call)
 {
 case DLL_PROCESS_ATTACH:
  {
   //_CRT_INIT(hModule,ul_reason_for_call,lpReserved);}
于 2013-03-07T10:22:54.513 に答える