GetOpenFileNameのカスタムについて
Posted: 2018年6月28日(木) 16:21
題の通りです。GetOpenFileNameをカスタムしてメモリを動的確保しようと思っているのですがうまくいきません。
//ヘッダファイル
//ソースファイル
//呼び出し
すると
どこでそうなっているのでしょう...?
//ヘッダファイル
#include <Windows.h>
class GetOpenFileDir
{
public:
GetOpenFileDir();
GetOpenFileDir( GetOpenFileDir& ) = delete;
~GetOpenFileDir();
int run( HWND hWnd );
private:
static TCHAR* _expandMem( TCHAR* _OldString,const size_t& Size );
private:
static UINT_PTR CALLBACK OFNHook( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
bool _isChoseDir; //ディレクトリを選択するかどうか
TCHAR* _chosed;
TCHAR _chosed_s[32];
OPENFILENAME _ofn; //カスタムしていく構造体
};
GetOpenFileDir::GetOpenFileDir() :
_isChoseDir(), _chosed(), _ofn()
{
}
GetOpenFileDir::~GetOpenFileDir()
{
free( _chosed );
_chosed = nullptr;
}
int GetOpenFileDir::run( HWND hWnd )
{
_ofn.lStructSize = sizeof( OPENFILENAME );
_ofn.hwndOwner = hWnd;
_ofn.lpstrFile = _chosed_s;
_ofn.nMaxFile = std::size( _chosed_s );
_ofn.Flags |= OFN_EXPLORER | //Explorer Style
OFN_ENABLESIZING | //サイズを変更できるようにする
OFN_ENABLEHOOK; //フックプロシージャを使う
_ofn.lpfnHook = OFNHook;
_ofn.lCustData = reinterpret_cast<LPARAM>( &( *this ) );
auto _Ret = GetOpenFileName( &_ofn );
_ofn.lCustData = 0;
return _Ret;
}
TCHAR* GetOpenFileDir::_expandMem( TCHAR* _OldString, const size_t& Size )
{
return reinterpret_cast<TCHAR*>(
( _OldString == nullptr ) ?
calloc( Size, sizeof( TCHAR ) ) :
_recalloc( _OldString, Size , sizeof( TCHAR ) ) );
}
UINT_PTR GetOpenFileDir::OFNHook( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch (uMsg) {
case WM_INITDIALOG:
return TRUE;
case WM_NOTIFY:{
LPOFNOTIFY lpFnNotify = reinterpret_cast<LPOFNOTIFY>( lParam );
auto* _This = reinterpret_cast<GetOpenFileDir*>( lpFnNotify->lpOFN->lCustData );
switch (lpFnNotify->hdr.code) {
case CDN_FILEOK: {
//ファイル名を取得する
auto _Parent = GetParent( hDlg );
auto _Size = CommDlg_OpenSave_GetFilePath( _Parent, nullptr, 0 );
if (_Size > std::size( _This->_chosed_s )) {
_This->_chosed = _expandMem( _This->_chosed, _Size );
CommDlg_OpenSave_GetFilePath( _Parent, _This->_chosed, _Size );
ZeroMemory( _This->_chosed_s, sizeof( _This->_chosed_s ) );
}
return TRUE;
}
case CDN_FOLDERCHANGE: {
return TRUE;
}
}
}
}
return FALSE;
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
GetOpenFileDir _Dir;
_Dir.run( nullptr );
return 0;
}
となるのですがどこでそうなっているのかを特定できません。Run-Time Check Failure #2 - Stack around the variable '_Dir' was corrupted.
どこでそうなっているのでしょう...?