質問編集履歴
8
解決策を追加した
test
CHANGED
File without changes
|
test
CHANGED
@@ -437,3 +437,9 @@
|
|
437
437
|
マシンC (Windows 10 Home x86)
|
438
438
|
|
439
439
|
マシンD (Windows 7 Professional x64)
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
###解決策 (by catsforepawさん)
|
444
|
+
|
445
|
+
**CoInitialize**と**CoUninitialize**を呼ぶようにする。
|
7
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -410,6 +410,8 @@
|
|
410
410
|
|
411
411
|
マシンC … その次に試したマシン => マシンAとマシンBでビルドしたexeを実行 => どちらも異常なし
|
412
412
|
|
413
|
+
マシンD … その後試したマシン => マシンAとマシンBでビルドしたexeを実行 => どちらも実行時に強制終了
|
414
|
+
|
413
415
|
|
414
416
|
|
415
417
|
その後マシンAを再起動させてもう一度コンパイル・実行したところ
|
6
test
CHANGED
File without changes
|
test
CHANGED
@@ -433,3 +433,5 @@
|
|
433
433
|
マシンB (Windows 10 Pro x64)
|
434
434
|
|
435
435
|
マシンC (Windows 10 Home x86)
|
436
|
+
|
437
|
+
マシンD (Windows 7 Professional x64)
|
5
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -404,11 +404,11 @@
|
|
404
404
|
|
405
405
|
特に強制終了することなく動作しました。
|
406
406
|
|
407
|
-
マシンA
|
407
|
+
マシンA … 最初に試したマシン => コンパイル・実行 => 実行時に強制終了
|
408
|
-
|
408
|
+
|
409
|
-
マシンB
|
409
|
+
マシンB … 次に試したマシン => コンパイル・実行 => 異常なし
|
410
|
-
|
410
|
+
|
411
|
-
マシンC
|
411
|
+
マシンC … その次に試したマシン => マシンAとマシンBでビルドしたexeを実行 => どちらも異常なし
|
412
412
|
|
413
413
|
|
414
414
|
|
@@ -425,3 +425,11 @@
|
|
425
425
|
Direct2D (d2d1.h) (d2d1.lib) (dxguid.lib)
|
426
426
|
|
427
427
|
WIC (wincodec.h) (windowscodecs.lib)
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
マシンA (Windows 7 Ultimate x64)
|
432
|
+
|
433
|
+
マシンB (Windows 10 Pro x64)
|
434
|
+
|
435
|
+
マシンC (Windows 10 Home x86)
|
4
試したことを追加した。
test
CHANGED
File without changes
|
test
CHANGED
@@ -398,6 +398,26 @@
|
|
398
398
|
|
399
399
|
|
400
400
|
|
401
|
+
**7/4追記**
|
402
|
+
|
403
|
+
別のマシンでコンパイル・実行したところ
|
404
|
+
|
405
|
+
特に強制終了することなく動作しました。
|
406
|
+
|
407
|
+
マシンA (Windows 7 Ultimate x64) … 最初に試したマシン => コンパイル・実行 => 実行時に強制終了
|
408
|
+
|
409
|
+
マシンB (Windows 10 Pro x64) … 次に試したマシン => コンパイル・実行 => 異常なし
|
410
|
+
|
411
|
+
マシンC (Windows 10 Home x86) … その次に試したマシン => マシンBでビルドしたexeを実行 => 異常なし
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
その後マシンAを再起動させてもう一度コンパイル・実行したところ
|
416
|
+
|
417
|
+
実行時に強制終了してしまいました。
|
418
|
+
|
419
|
+
|
420
|
+
|
401
421
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
402
422
|
|
403
423
|
Visual Studio Commnunity 2015
|
3
コメントをつけた。
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
7/4更新
|
34
34
|
|
35
|
-
(ファイルを分けて
|
35
|
+
(実際はファイルを分けてコードを書いてあります。)
|
36
36
|
|
37
37
|
```C++
|
38
38
|
|
2
コードを更新した。
test
CHANGED
File without changes
|
test
CHANGED
@@ -96,31 +96,23 @@
|
|
96
96
|
|
97
97
|
// Direct2Dの初期化処理を行う
|
98
98
|
|
99
|
-
|
99
|
+
void initializeDirect2D()
|
100
|
-
|
100
|
+
|
101
|
-
{
|
101
|
+
{
|
102
|
-
|
103
|
-
HRESULT result;
|
104
|
-
|
105
|
-
|
106
102
|
|
107
103
|
// Direct2Dファクトリを生成する
|
108
104
|
|
109
|
-
|
105
|
+
D2D1CreateFactory(
|
110
106
|
|
111
107
|
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
112
108
|
|
113
109
|
&direct2DFactory);
|
114
110
|
|
115
|
-
if (FAILED(result))
|
116
|
-
|
117
|
-
return false;
|
118
|
-
|
119
111
|
|
120
112
|
|
121
113
|
// レンダーターゲットを生成する
|
122
114
|
|
123
|
-
|
115
|
+
direct2DFactory->CreateHwndRenderTarget(
|
124
116
|
|
125
117
|
D2D1::RenderTargetProperties(),
|
126
118
|
|
@@ -132,23 +124,11 @@
|
|
132
124
|
|
133
125
|
&renderTarget);
|
134
126
|
|
135
|
-
if (FAILED(result))
|
136
|
-
|
137
|
-
return false;
|
138
|
-
|
139
127
|
|
140
128
|
|
141
129
|
// ブラシを生成する
|
142
130
|
|
143
|
-
re
|
131
|
+
renderTarget->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0), &brush);
|
144
|
-
|
145
|
-
if (FAILED(result))
|
146
|
-
|
147
|
-
return false;
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
return true;
|
152
132
|
|
153
133
|
}
|
154
134
|
|
@@ -216,13 +196,9 @@
|
|
216
196
|
|
217
197
|
{
|
218
198
|
|
219
|
-
HRESULT result;
|
220
|
-
|
221
|
-
|
222
|
-
|
223
199
|
// WICイメージングファクトリを生成する
|
224
200
|
|
225
|
-
|
201
|
+
CoCreateInstance(
|
226
202
|
|
227
203
|
CLSID_WICImagingFactory,
|
228
204
|
|
@@ -234,15 +210,11 @@
|
|
234
210
|
|
235
211
|
(LPVOID*)&wicImagingFactory);
|
236
212
|
|
237
|
-
if (FAILED(result))
|
238
|
-
|
239
|
-
return;
|
240
|
-
|
241
213
|
|
242
214
|
|
243
215
|
// Bitmapデコーダを生成する
|
244
216
|
|
245
|
-
|
217
|
+
wicImagingFactory->CreateDecoderFromFilename(
|
246
218
|
|
247
219
|
fileName,
|
248
220
|
|
@@ -254,35 +226,23 @@
|
|
254
226
|
|
255
227
|
&wicBitmapDecoder);
|
256
228
|
|
257
|
-
if (FAILED(result))
|
258
|
-
|
259
|
-
return;
|
260
|
-
|
261
229
|
|
262
230
|
|
263
231
|
// 画像からフレームを読み込む
|
264
232
|
|
265
|
-
|
233
|
+
wicBitmapDecoder->GetFrame(0, &wicBitmapFrame);
|
266
|
-
|
267
|
-
if (FAILED(result))
|
268
|
-
|
269
|
-
return;
|
270
234
|
|
271
235
|
|
272
236
|
|
273
237
|
// フォーマットコンバータを生成する
|
274
238
|
|
275
|
-
|
239
|
+
wicImagingFactory->CreateFormatConverter(&wicFormatConverter);
|
276
|
-
|
277
|
-
if (FAILED(result))
|
278
|
-
|
279
|
-
return;
|
280
240
|
|
281
241
|
|
282
242
|
|
283
243
|
// コンバータの初期化をする
|
284
244
|
|
285
|
-
|
245
|
+
wicFormatConverter->Initialize(
|
286
246
|
|
287
247
|
wicBitmapFrame,
|
288
248
|
|
@@ -296,15 +256,11 @@
|
|
296
256
|
|
297
257
|
WICBitmapPaletteTypeCustom);
|
298
258
|
|
299
|
-
if (FAILED(result))
|
300
|
-
|
301
|
-
return;
|
302
|
-
|
303
259
|
|
304
260
|
|
305
261
|
// Bitmapを生成する
|
306
262
|
|
307
|
-
re
|
263
|
+
renderTarget->CreateBitmapFromWicBitmap(
|
308
264
|
|
309
265
|
wicFormatConverter,
|
310
266
|
|
@@ -312,10 +268,6 @@
|
|
312
268
|
|
313
269
|
&bitmap);
|
314
270
|
|
315
|
-
if (FAILED(result))
|
316
|
-
|
317
|
-
return;
|
318
|
-
|
319
271
|
}
|
320
272
|
|
321
273
|
|
@@ -370,25 +322,19 @@
|
|
370
322
|
|
371
323
|
// ウィンドウを生成する
|
372
324
|
|
373
|
-
i
|
325
|
+
initializeWin32API();
|
374
|
-
|
375
|
-
return -1;
|
376
326
|
|
377
327
|
|
378
328
|
|
379
329
|
// Direct2Dの初期化処理を行う
|
380
330
|
|
381
|
-
i
|
331
|
+
initializeDirect2D();
|
382
|
-
|
383
|
-
return -1;
|
384
332
|
|
385
333
|
|
386
334
|
|
387
335
|
// DirectInputの初期化処理を行う
|
388
336
|
|
389
|
-
i
|
337
|
+
initializeDirectInput();
|
390
|
-
|
391
|
-
return -1;
|
392
338
|
|
393
339
|
|
394
340
|
|
1
コードを追加した。
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,8 +30,158 @@
|
|
30
30
|
|
31
31
|
###該当のソースコード
|
32
32
|
|
33
|
+
7/4更新
|
34
|
+
|
35
|
+
(ファイルを分けてあるコードも今はまとめて1つファイルに書いています。)
|
36
|
+
|
33
37
|
```C++
|
34
38
|
|
39
|
+
#include <d2d1.h>
|
40
|
+
|
41
|
+
#include <wincodec.h>
|
42
|
+
|
43
|
+
#include <map>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
#pragma comment(lib, "d2d1.lib")
|
48
|
+
|
49
|
+
#pragma comment(lib, "dxguid.lib")
|
50
|
+
|
51
|
+
#pragma comment(lib, "windowscodecs.lib")
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
// ウィンドウの幅
|
56
|
+
|
57
|
+
extern int WINDOW_WIDTH;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
// ウィンドウの高さ
|
62
|
+
|
63
|
+
extern int WINDOW_HEIGHT;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
// アプリケーションのインスタンスハンドル
|
68
|
+
|
69
|
+
extern HINSTANCE applicationInstance;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
// ウィンドウハンドル
|
74
|
+
|
75
|
+
extern HWND windowHandle;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
// Direct2Dファクトリ
|
80
|
+
|
81
|
+
ID2D1Factory*direct2DFactory = NULL;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
// レンダーターゲット
|
86
|
+
|
87
|
+
ID2D1HwndRenderTarget* renderTarget = NULL;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// ブラシ
|
92
|
+
|
93
|
+
ID2D1SolidColorBrush* brush = NULL;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
// Direct2Dの初期化処理を行う
|
98
|
+
|
99
|
+
bool initializeDirect2D()
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
HRESULT result;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
// Direct2Dファクトリを生成する
|
108
|
+
|
109
|
+
result = D2D1CreateFactory(
|
110
|
+
|
111
|
+
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
112
|
+
|
113
|
+
&direct2DFactory);
|
114
|
+
|
115
|
+
if (FAILED(result))
|
116
|
+
|
117
|
+
return false;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
// レンダーターゲットを生成する
|
122
|
+
|
123
|
+
result = direct2DFactory->CreateHwndRenderTarget(
|
124
|
+
|
125
|
+
D2D1::RenderTargetProperties(),
|
126
|
+
|
127
|
+
D2D1::HwndRenderTargetProperties(
|
128
|
+
|
129
|
+
windowHandle,
|
130
|
+
|
131
|
+
D2D1::SizeU(WINDOW_WIDTH, WINDOW_HEIGHT)),
|
132
|
+
|
133
|
+
&renderTarget);
|
134
|
+
|
135
|
+
if (FAILED(result))
|
136
|
+
|
137
|
+
return false;
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
// ブラシを生成する
|
142
|
+
|
143
|
+
result = renderTarget->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0), &brush);
|
144
|
+
|
145
|
+
if (FAILED(result))
|
146
|
+
|
147
|
+
return false;
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
return true;
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
// Direct2Dの終了処理を行う
|
158
|
+
|
159
|
+
void finalizeDirect2D()
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
OutputDebugString("brushをReleaseします!\n");
|
164
|
+
|
165
|
+
if (brush != NULL)
|
166
|
+
|
167
|
+
brush->Release();
|
168
|
+
|
169
|
+
OutputDebugString("renderTargetをReleaseします!\n");
|
170
|
+
|
171
|
+
if (renderTarget != NULL)
|
172
|
+
|
173
|
+
renderTarget->Release();
|
174
|
+
|
175
|
+
OutputDebugString("direct2DFactoryをReleaseします!\n");
|
176
|
+
|
177
|
+
if (direct2DFactory != NULL)
|
178
|
+
|
179
|
+
direct2DFactory->Release();
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
35
185
|
class Image
|
36
186
|
|
37
187
|
{
|
@@ -42,7 +192,7 @@
|
|
42
192
|
|
43
193
|
~Image();
|
44
194
|
|
45
|
-
void draw(float x, float y)
|
195
|
+
void draw(float x, float y);
|
46
196
|
|
47
197
|
|
48
198
|
|
@@ -66,9 +216,13 @@
|
|
66
216
|
|
67
217
|
{
|
68
218
|
|
219
|
+
HRESULT result;
|
220
|
+
|
221
|
+
|
222
|
+
|
69
223
|
// WICイメージングファクトリを生成する
|
70
224
|
|
71
|
-
CoCreateInstance(
|
225
|
+
result = CoCreateInstance(
|
72
226
|
|
73
227
|
CLSID_WICImagingFactory,
|
74
228
|
|
@@ -80,11 +234,15 @@
|
|
80
234
|
|
81
235
|
(LPVOID*)&wicImagingFactory);
|
82
236
|
|
237
|
+
if (FAILED(result))
|
238
|
+
|
239
|
+
return;
|
240
|
+
|
83
241
|
|
84
242
|
|
85
243
|
// Bitmapデコーダを生成する
|
86
244
|
|
87
|
-
wicImagingFactory->CreateDecoderFromFilename(
|
245
|
+
result = wicImagingFactory->CreateDecoderFromFilename(
|
88
246
|
|
89
247
|
fileName,
|
90
248
|
|
@@ -96,23 +254,35 @@
|
|
96
254
|
|
97
255
|
&wicBitmapDecoder);
|
98
256
|
|
257
|
+
if (FAILED(result))
|
258
|
+
|
259
|
+
return;
|
260
|
+
|
99
261
|
|
100
262
|
|
101
263
|
// 画像からフレームを読み込む
|
102
264
|
|
103
|
-
wicBitmapDecoder->GetFrame(0, &wicBitmapFrame);
|
265
|
+
result = wicBitmapDecoder->GetFrame(0, &wicBitmapFrame);
|
266
|
+
|
267
|
+
if (FAILED(result))
|
268
|
+
|
269
|
+
return;
|
104
270
|
|
105
271
|
|
106
272
|
|
107
273
|
// フォーマットコンバータを生成する
|
108
274
|
|
109
|
-
wicImagingFactory->CreateFormatConverter(&wicFormatConverter);
|
275
|
+
result = wicImagingFactory->CreateFormatConverter(&wicFormatConverter);
|
276
|
+
|
277
|
+
if (FAILED(result))
|
278
|
+
|
279
|
+
return;
|
110
280
|
|
111
281
|
|
112
282
|
|
113
283
|
// コンバータの初期化をする
|
114
284
|
|
115
|
-
wicFormatConverter->Initialize(
|
285
|
+
result = wicFormatConverter->Initialize(
|
116
286
|
|
117
287
|
wicBitmapFrame,
|
118
288
|
|
@@ -126,11 +296,15 @@
|
|
126
296
|
|
127
297
|
WICBitmapPaletteTypeCustom);
|
128
298
|
|
299
|
+
if (FAILED(result))
|
300
|
+
|
301
|
+
return;
|
302
|
+
|
129
303
|
|
130
304
|
|
131
305
|
// Bitmapを生成する
|
132
306
|
|
133
|
-
renderTarget->CreateBitmapFromWicBitmap(
|
307
|
+
result = renderTarget->CreateBitmapFromWicBitmap(
|
134
308
|
|
135
309
|
wicFormatConverter,
|
136
310
|
|
@@ -138,6 +312,10 @@
|
|
138
312
|
|
139
313
|
&bitmap);
|
140
314
|
|
315
|
+
if (FAILED(result))
|
316
|
+
|
317
|
+
return;
|
318
|
+
|
141
319
|
}
|
142
320
|
|
143
321
|
|
@@ -146,30 +324,122 @@
|
|
146
324
|
|
147
325
|
{
|
148
326
|
|
327
|
+
OutputDebugString("bitmapをReleaseします!\n");
|
328
|
+
|
329
|
+
if (bitmap != NULL)
|
330
|
+
|
331
|
+
bitmap->Release();
|
332
|
+
|
333
|
+
OutputDebugString("wicFormatConverterをReleaseします!\n");
|
334
|
+
|
335
|
+
if (wicFormatConverter != NULL)
|
336
|
+
|
337
|
+
wicFormatConverter->Release();
|
338
|
+
|
339
|
+
OutputDebugString("wicBitmapFrameをReleaseします!\n");
|
340
|
+
|
341
|
+
if (wicBitmapFrame != NULL)
|
342
|
+
|
343
|
+
wicBitmapFrame->Release();
|
344
|
+
|
345
|
+
OutputDebugString("wicBitmapDecoderをReleaseします!\n");
|
346
|
+
|
347
|
+
if (wicBitmapDecoder != NULL)
|
348
|
+
|
349
|
+
wicBitmapDecoder->Release();
|
350
|
+
|
351
|
+
OutputDebugString("wicImagingFactoryをReleaseします!\n");
|
352
|
+
|
149
353
|
if (wicImagingFactory != NULL)
|
150
354
|
|
151
355
|
wicImagingFactory->Release();
|
152
356
|
|
153
|
-
if (wicBitmapDecoder != NULL)
|
154
|
-
|
155
|
-
wicBitmapDecoder->Release();
|
156
|
-
|
157
|
-
if (wicBitmapFrame != NULL)
|
158
|
-
|
159
|
-
wicBitmapFrame->Release();
|
160
|
-
|
161
|
-
if (wicFormatConverter != NULL)
|
162
|
-
|
163
|
-
wicFormatConverter->Release();
|
164
|
-
|
165
|
-
if (bitmap != NULL)
|
166
|
-
|
167
|
-
bitmap->Release();
|
168
|
-
|
169
357
|
}
|
170
358
|
|
359
|
+
|
360
|
+
|
361
|
+
void Image::draw(float x, float y){}
|
362
|
+
|
171
363
|
```
|
172
364
|
|
365
|
+
```C++
|
366
|
+
|
367
|
+
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
368
|
+
|
369
|
+
{
|
370
|
+
|
371
|
+
// ウィンドウを生成する
|
372
|
+
|
373
|
+
if (!initializeWin32API())
|
374
|
+
|
375
|
+
return -1;
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
// Direct2Dの初期化処理を行う
|
380
|
+
|
381
|
+
if (!initializeDirect2D())
|
382
|
+
|
383
|
+
return -1;
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
// DirectInputの初期化処理を行う
|
388
|
+
|
389
|
+
if (!initializeDirectInput())
|
390
|
+
|
391
|
+
return -1;
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
Image* image = new Image(L"hoge.png");
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
// 終了メッセージが送られるまでループする
|
400
|
+
|
401
|
+
while (checkMessage())
|
402
|
+
|
403
|
+
{
|
404
|
+
|
405
|
+
beginRendering();
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
clearScreen(1, 1, 1);
|
410
|
+
|
411
|
+
image->draw(0, 0);
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
endRendering();
|
416
|
+
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
delete image;
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
// Direct2Dの終了処理を行う
|
426
|
+
|
427
|
+
finalizeDirect2D();
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
// DirectInputの終了処理を行う
|
432
|
+
|
433
|
+
finalizeDirectInput();
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
return 0;
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
```
|
442
|
+
|
173
443
|
|
174
444
|
|
175
445
|
###試したこと
|