質問編集履歴

1

追記

2017/06/05 03:38

投稿

BeatStar
BeatStar

スコア4958

test CHANGED
File without changes
test CHANGED
@@ -565,3 +565,181 @@
565
565
 
566
566
 
567
567
  宜しくお願い致します。
568
+
569
+
570
+
571
+
572
+
573
+ -----------------------
574
+
575
+
576
+
577
+ [追記]
578
+
579
+
580
+
581
+ ```C++
582
+
583
+ // Original.cpp
584
+
585
+ // 必要なヘッダはインクルードされていて、リンクもされているとして。
586
+
587
+
588
+
589
+
590
+
591
+ /*
592
+
593
+ class CThread1 : public IThread{
594
+
595
+ public:
596
+
597
+ CThread1() throw(int){
598
+
599
+ try{
600
+
601
+ Console = new CConsole();
602
+
603
+ }catch( int e ){
604
+
605
+ throw -1;
606
+
607
+ }
608
+
609
+ }
610
+
611
+
612
+
613
+ ~CThread1(){
614
+
615
+ delete Console;
616
+
617
+ }
618
+
619
+
620
+
621
+ void Execute( void ){
622
+
623
+ Console->Write( "C++" );
624
+
625
+ Console->Wait();
626
+
627
+ }
628
+
629
+ private:
630
+
631
+ CConsole* Console;
632
+
633
+ };
634
+
635
+
636
+
637
+ class CThread2 : public IThread{
638
+
639
+ public:
640
+
641
+ CThread2() throw(int){
642
+
643
+ try{
644
+
645
+ Console = new CConsole();
646
+
647
+ }catch( int e ){
648
+
649
+ throw -2;
650
+
651
+ }
652
+
653
+ }
654
+
655
+
656
+
657
+ ~CThread2(){
658
+
659
+ delete Console;
660
+
661
+ }
662
+
663
+
664
+
665
+ void Execute( void ){
666
+
667
+ Console->Write( "Java" );
668
+
669
+ Console->Wait();
670
+
671
+ }
672
+
673
+ private:
674
+
675
+ CConsole* Console;
676
+
677
+ };
678
+
679
+
680
+
681
+ CThread1* thread1;
682
+
683
+ CThread2* thread2;
684
+
685
+
686
+
687
+
688
+
689
+ void func( void ){
690
+
691
+ // CConsole* Console;
692
+
693
+ try{
694
+
695
+ thread1 = new CThread1();
696
+
697
+ thread2 = new CThread2();
698
+
699
+ thread1->Execute();
700
+
701
+ }catch( int e ){
702
+
703
+ if( e == -1 ) MessageBox( NULL, "例外 (for Thread1) が投げられた", "エラー", MB_OK );
704
+
705
+ else MessageBox( NULL, "例外 (for Thread2) が投げられた", "エラー", MB_OK );
706
+
707
+ }
708
+
709
+ }
710
+
711
+
712
+
713
+ void end(void){
714
+
715
+ delete thread1;
716
+
717
+ delete thread2;
718
+
719
+ }
720
+
721
+ ```
722
+
723
+
724
+
725
+ という感じでやっています。
726
+
727
+
728
+
729
+
730
+
731
+ WM_CREATEのときに func関数を呼び出して、
732
+
733
+
734
+
735
+ WM_DESTROYでend関数で破棄。
736
+
737
+
738
+
739
+ という感じです。
740
+
741
+
742
+
743
+ CConsoleっていうクラスは コンソールを担当する自作クラスで、多分問題ない(これが原因じゃない)と思います。
744
+
745
+ ( 同じGUIでも Boost::threadで動かすと普通に動きましたから。例外は投げられましたが。今回は関係がないかも。 )