<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Snapshot file save error in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Snapshot-file-save-error/m-p/1058438#M53004</link>
    <description>&lt;P&gt;I've created a tool to take a snapshot of a gesture in order to create libraries for gesture recognition. It records finger and joint data from a single frame into an edit box. The user then clicks "save snapshot" to add the snapshot to a library by appending the data to a text file. This might help other developers, but I'm not ready to release it with this annoying bug. It still works, but you have to restart the program after saving one or two gesture&lt;/P&gt;

&lt;P&gt;It does so successfully, appending one or two poses, then it crashes. Any insight would be appreciated.&lt;/P&gt;

&lt;P&gt;Here's my code:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;using namespace std;
BOOL GetSaveSnapshot(HWND hDlg)
{

	TCHAR   szFile[MAX_PATH] = TEXT("\0");
	OPENFILENAME   ofn;
	HANDLE hFile = INVALID_HANDLE_VALUE;

	HWND hEdit = NULL;
	DWORD dwTextLen = 0, bytesWritten = 0;
	TCHAR *wszEditText = NULL;
	char *szEditText = NULL;



	hEdit = GetDlgItem(hDlg, IDC_GESTURELIBRARY);
	//get the text length of the edit controls contents
	dwTextLen = GetWindowTextLength(hEdit);
	wszEditText = (TCHAR*)malloc((dwTextLen + 1)*sizeof(TCHAR));
	memset(wszEditText, 0, (dwTextLen + 1)*sizeof(TCHAR));
	//read edit controls contents into buffer
	GetWindowText(hEdit, wszEditText, dwTextLen + 1);
	szEditText = (char*)malloc(dwTextLen + 1);
	//convert the wide char read from edit control to char
	//wcstombs(szEditText, wszEditText, dwTextLen);
	String fileName;
	fileName = (std::wstring)wszEditText;
	fileName += L".txt";
	

	memset(&amp;amp;(ofn), 0, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hDlg;
	ofn.lpstrFile = wszEditText;
	ofn.nMaxFile = MAX_PATH;
	//ofn.lpstrFilter = L"RSSDK clip (*.rssdk)\0*.rssdk\0All Files (*.*)\0*.*\0";
	ofn.lpstrFilter = TEXT("Text (*.txt)\0*.txt\0");
	//ofn.lpstrTitle = TEXT("Save File As");
	ofn.lpstrTitle = wszEditText;
	ofn.Flags = OFN_HIDEREADONLY;
	ofn.lpstrDefExt = TEXT("txt");
	//get the filename the user wants to save to
	ofn.lpstrFileTitle = wszEditText;
	if (GetSaveFileName(&amp;amp;ofn))
	{


		//ofn.lpstrFile contains the full path of the file, get a handle to it
		
		if (GetLibraryState(hDlg)) {

			hFile = CreateFile(ofn.lpstrFile, FILE_APPEND_DATA, FILE_SHARE_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
			SetFilePointer(hFile, 0, 0, FILE_END);	
		}
		else{
			hFile = CreateFile(ofn.lpstrFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			
		}
		if (hFile == INVALID_HANDLE_VALUE)
			return FALSE;

		hEdit = GetDlgItem(hDlg, IDC_MOCAPDATA);	
		//get the text length of the edit controls contents
		dwTextLen = GetWindowTextLength(hEdit);
		wszEditText = (TCHAR*)malloc((dwTextLen + 1)*sizeof(TCHAR));
		memset(wszEditText, 0, (dwTextLen + 1)*sizeof(TCHAR));
		//read edit controls contents into buffer
		GetWindowText(hEdit, wszEditText, dwTextLen + 1);
		szEditText = (char*)malloc(dwTextLen + 1);
		//convert the wide char read from edit control to char
		wcstombs(szEditText, wszEditText, dwTextLen);
		//save the contents into file
		if (WriteFile(hFile, szEditText, dwTextLen, &amp;amp;bytesWritten, NULL))

		//free resources
		free(wszEditText);
		free(szEditText);
		CloseHandle(hFile);
	}
	return TRUE;
}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jan 2015 13:53:28 GMT</pubDate>
    <dc:creator>Scott_W_1</dc:creator>
    <dc:date>2015-01-23T13:53:28Z</dc:date>
    <item>
      <title>Snapshot file save error</title>
      <link>https://community.intel.com/t5/Software-Archive/Snapshot-file-save-error/m-p/1058438#M53004</link>
      <description>&lt;P&gt;I've created a tool to take a snapshot of a gesture in order to create libraries for gesture recognition. It records finger and joint data from a single frame into an edit box. The user then clicks "save snapshot" to add the snapshot to a library by appending the data to a text file. This might help other developers, but I'm not ready to release it with this annoying bug. It still works, but you have to restart the program after saving one or two gesture&lt;/P&gt;

&lt;P&gt;It does so successfully, appending one or two poses, then it crashes. Any insight would be appreciated.&lt;/P&gt;

&lt;P&gt;Here's my code:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;using namespace std;
BOOL GetSaveSnapshot(HWND hDlg)
{

	TCHAR   szFile[MAX_PATH] = TEXT("\0");
	OPENFILENAME   ofn;
	HANDLE hFile = INVALID_HANDLE_VALUE;

	HWND hEdit = NULL;
	DWORD dwTextLen = 0, bytesWritten = 0;
	TCHAR *wszEditText = NULL;
	char *szEditText = NULL;



	hEdit = GetDlgItem(hDlg, IDC_GESTURELIBRARY);
	//get the text length of the edit controls contents
	dwTextLen = GetWindowTextLength(hEdit);
	wszEditText = (TCHAR*)malloc((dwTextLen + 1)*sizeof(TCHAR));
	memset(wszEditText, 0, (dwTextLen + 1)*sizeof(TCHAR));
	//read edit controls contents into buffer
	GetWindowText(hEdit, wszEditText, dwTextLen + 1);
	szEditText = (char*)malloc(dwTextLen + 1);
	//convert the wide char read from edit control to char
	//wcstombs(szEditText, wszEditText, dwTextLen);
	String fileName;
	fileName = (std::wstring)wszEditText;
	fileName += L".txt";
	

	memset(&amp;amp;(ofn), 0, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hDlg;
	ofn.lpstrFile = wszEditText;
	ofn.nMaxFile = MAX_PATH;
	//ofn.lpstrFilter = L"RSSDK clip (*.rssdk)\0*.rssdk\0All Files (*.*)\0*.*\0";
	ofn.lpstrFilter = TEXT("Text (*.txt)\0*.txt\0");
	//ofn.lpstrTitle = TEXT("Save File As");
	ofn.lpstrTitle = wszEditText;
	ofn.Flags = OFN_HIDEREADONLY;
	ofn.lpstrDefExt = TEXT("txt");
	//get the filename the user wants to save to
	ofn.lpstrFileTitle = wszEditText;
	if (GetSaveFileName(&amp;amp;ofn))
	{


		//ofn.lpstrFile contains the full path of the file, get a handle to it
		
		if (GetLibraryState(hDlg)) {

			hFile = CreateFile(ofn.lpstrFile, FILE_APPEND_DATA, FILE_SHARE_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
			SetFilePointer(hFile, 0, 0, FILE_END);	
		}
		else{
			hFile = CreateFile(ofn.lpstrFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			
		}
		if (hFile == INVALID_HANDLE_VALUE)
			return FALSE;

		hEdit = GetDlgItem(hDlg, IDC_MOCAPDATA);	
		//get the text length of the edit controls contents
		dwTextLen = GetWindowTextLength(hEdit);
		wszEditText = (TCHAR*)malloc((dwTextLen + 1)*sizeof(TCHAR));
		memset(wszEditText, 0, (dwTextLen + 1)*sizeof(TCHAR));
		//read edit controls contents into buffer
		GetWindowText(hEdit, wszEditText, dwTextLen + 1);
		szEditText = (char*)malloc(dwTextLen + 1);
		//convert the wide char read from edit control to char
		wcstombs(szEditText, wszEditText, dwTextLen);
		//save the contents into file
		if (WriteFile(hFile, szEditText, dwTextLen, &amp;amp;bytesWritten, NULL))

		//free resources
		free(wszEditText);
		free(szEditText);
		CloseHandle(hFile);
	}
	return TRUE;
}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 13:53:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Snapshot-file-save-error/m-p/1058438#M53004</guid>
      <dc:creator>Scott_W_1</dc:creator>
      <dc:date>2015-01-23T13:53:28Z</dc:date>
    </item>
  </channel>
</rss>

