c++ builder XE4, 10.2 Tokyo > 다른 앱 열기 > access violation이 나왔다 > ZeroMemory() 하면 피할 수 있었다

동작 확인
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

주의



(추기 2018/11/14)

아래에서 사용하는 ZeroMemory는 최적화로 날아가므로 SecureZeroMemory()를 사용하는 것이 좋습니다.
  • C++ > SecureZeroMemory() > 최적화로 날아가는 ZeroMemory()의 대안

  • 내용



    ぃ tp // m / 7 ~ f9 / ms / 95f72 ~ 80 ~ 8807018fb
    에서 만든 앱을 childProject.exe로 이름을 바꾸고 다른 앱에서 엽니다.

    다른 앱 시작

    XE4



    try1 > access violation



    Unit1.cpp
    void __fastcall TParentForm::App_openOther()
    {
        String param = L"/caption=Test_1_B_C";
    
        String progname = L"childProject.exe";
        if (FileExists(progname) == false) {
            ShowMessage(L"childProejct.exe not found");
            return;
        }
    
        TShellExecuteInfo sinfo;
        sinfo.cbSize = sizeof(sinfo);
        sinfo.hwnd = 0; // Desktop
        sinfo.fMask = SEE_MASK_FLAG_DDEWAIT;
        sinfo.lpFile = progname.c_str();
        sinfo.lpParameters = param.c_str();
        sinfo.lpVerb = L"";
        sinfo.nShow = SW_SHOWNORMAL;
    
        ShellExecuteEx(&sinfo);
    
        // 起動待ち
        WaitForInputIdle(sinfo.hProcess, INFINITE);
    }
    void __fastcall TParentForm::Button1Click(TObject *Sender)
    {
        App_openOther();
    }
    //---------------------------------------------------------------------------
    

    ShellExecuteEx(&sinfo);
    실행 직후에 다음 오류가 발생합니다. 조사 중.



    try2 > no error



    h tp // w w. 우세 후루코로. 네 t/2006/12/포 st_34. HTML
    가 도움이 되었다.

    Unit.cpp
    __fastcall TParentForm::TParentForm(TComponent* Owner)
        : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TParentForm::App_openOther()
    {
        String param = L"/caption=Test_1_B_C";
    
        String progname = L"childProject.exe";
        if (FileExists(progname) == false) {
            ShowMessage(L"childProejct.exe not found");
            return;
        }
    
        TShellExecuteInfo sinfo;
    
    #if 1
        ::ZeroMemory(&sinfo,sizeof(SHELLEXECUTEINFO));
    #endif
        sinfo.cbSize = sizeof(sinfo);
        sinfo.hwnd = 0; // Desktop
        sinfo.fMask = SEE_MASK_FLAG_DDEWAIT;
        sinfo.lpFile = progname.c_str();
        sinfo.lpParameters = param.c_str();
        sinfo.lpVerb = L"";
        sinfo.nShow = SW_SHOWNORMAL;
    
        ShellExecuteEx(&sinfo);
    
        // 起動待ち
        WaitForInputIdle(sinfo.hProcess, INFINITE);
    }
    void __fastcall TParentForm::Button1Click(TObject *Sender)
    {
        App_openOther();
    }
    //---------------------------------------------------------------------------
    
    #if 1 로 둘러싸인 부분이 있으면 위의 에러가 아니다.

    sinfo의 멤버 변수에 미초기화의 값이 들어가 있어 에러가 되고 있었던 것 같다.

    10.2 도쿄



    10.2 Tokyo의 경우 try1에서도 access violation이 되지 않았다.

    만약을 위해서는 try2의 방법으로 해 두는 것이 좋을 것이다.

    좋은 웹페이지 즐겨찾기