1
1
2
2
#define BLIT_IT_NATIVES_DLL_COMPILE
3
3
4
- #include " natives.h"
5
-
6
4
#include " threadutils.h"
7
5
6
+
7
+ #include " natives.h"
8
+
8
9
#include < list>
9
10
#include < string>
11
+ #include < vector>
10
12
11
13
#include < Windows.h>
14
+ #include < roapi.h>
12
15
13
16
using namespace std ;
14
17
18
+
19
+
15
20
struct ChooseFileContext
16
21
{
17
22
ChooseFileSuccessCallback _chooseFileSuccessCallback;
18
23
ChooseFileCancelledCallback _chooseFileCancelledCallback;
19
24
pthread_t file_picker_thread;
20
25
list<wstring> filetype_names;
21
26
list<wstring> filetype_extensions;
27
+ wchar_t * chosenFilename;
22
28
};
23
29
24
30
25
31
void * FilePickerThread (void * arg)
26
- {
32
+ {
27
33
ChooseFileContext* cfc = (ChooseFileContext*)arg;
28
34
29
- const int buf_len = 260 ;
30
- // TCHAR cwd[buf_len] = { 0 };
31
-
32
- // GetCurrentDirectory(buf_len, cwd);
35
+ const int buf_len = 261 ;
36
+ cfc->chosenFilename = new wchar_t [buf_len];
37
+ memset (cfc->chosenFilename , 0 , buf_len);
33
38
34
39
OPENFILENAME ofn; // common dialog box structure
35
- TCHAR szFile[buf_len]; // buffer for file name
36
- // HWND hwnd; // owner window
37
- // HANDLE hf; // file handle
38
-
39
-
40
40
41
41
// string test("G-code\0*.gcode\0All\0*.*\0");
42
42
wstring filetype_filters;
@@ -54,24 +54,20 @@ void* FilePickerThread(void* arg)
54
54
filetype_filters.push_back (' \0 ' );
55
55
filetype_filters += L" *.*" ;
56
56
filetype_filters.push_back (' \0 ' );
57
-
57
+ filetype_filters. push_back ( ' \0 ' );
58
58
59
59
// TCHAR filter[64] = TEXT(((const char*)test.c_str()));
60
60
61
- TCHAR* filter = (TCHAR*)filetype_filters.c_str ();
62
-
63
-
64
-
61
+ TCHAR* filter = (TCHAR*)filetype_filters.data ();
65
62
66
63
// Initialize OPENFILENAME
67
64
ZeroMemory (&ofn, sizeof (ofn));
68
65
ofn.lStructSize = sizeof (ofn);
69
66
// ofn.hwndOwner = hwnd;
70
- ofn.lpstrFile = szFile ;
67
+ ofn.lpstrFile = cfc-> chosenFilename ;
71
68
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
72
69
// use the contents of szFile to initialize itself.
73
- ofn.lpstrFile [0 ] = ' \0 ' ;
74
- ofn.nMaxFile = buf_len;
70
+ ofn.nMaxFile = buf_len - 1 ; // use -1 because we're paranoid that Windows will stupidly not include a null terminator
75
71
ofn.lpstrFilter = filter;
76
72
ofn.nFilterIndex = 1 ;
77
73
ofn.lpstrFileTitle = NULL ;
@@ -85,7 +81,9 @@ void* FilePickerThread(void* arg)
85
81
{
86
82
pthread_testcancel ();
87
83
if (cfc->_chooseFileSuccessCallback )
88
- cfc->_chooseFileSuccessCallback (ofn.lpstrFile );
84
+ {
85
+ cfc->_chooseFileSuccessCallback (cfc->chosenFilename );
86
+ }
89
87
}
90
88
else
91
89
{
@@ -103,6 +101,7 @@ void* __stdcall CreateChooseFileContext()
103
101
ChooseFileContext* cfc = new ChooseFileContext ();
104
102
cfc->_chooseFileCancelledCallback = NULL ;
105
103
cfc->_chooseFileSuccessCallback = NULL ;
104
+ cfc->chosenFilename = NULL ;
106
105
return cfc;
107
106
}
108
107
@@ -128,6 +127,9 @@ void __stdcall DestroyChooseFileContext(void* context)
128
127
{
129
128
ChooseFileContext* cfc = (ChooseFileContext*)context;
130
129
pthread_cancel (cfc->file_picker_thread );
130
+ pthread_join (cfc->file_picker_thread , NULL );
131
+ if (cfc->chosenFilename != NULL )
132
+ delete[] cfc->chosenFilename ;
131
133
delete cfc;
132
134
}
133
135
0 commit comments