Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. STL incompatible with Windows Forms?

STL incompatible with Windows Forms?

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++dotnetvisual-studiowinforms
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ricecake
    wrote on last edited by
    #1

    I have a strange problem that has been driving me up the wall. I created a SSCCE that shows my problem. Compile this with cl /EHsc /clr <filename>:

    #using <mscorlib.dll>
    #using <System.dll>
    #using <System.Windows.Forms.dll>

    #include <iostream>

    int main()
    {
    using System::Windows::Forms::DialogResult;
    using System::Windows::Forms::FolderBrowserDialog;
    using System::Windows::Forms::MessageBox;

    double d;
    std::cin >> d;
    
    FolderBrowserDialog\* fb = new FolderBrowserDialog;
    if (fb->ShowDialog() == DialogResult::OK) {
    	MessageBox::Show(fb->SelectedPath);
    }
    

    }

    When I run this program as is, after entering a number on the command line, the FolderBrowserDialog comes up blank. However, if I comment out the std::cin >> d; line, then the FolderBrowserDialog works fine. Does this happen for anybody else? Or am I misusing the mixture of managed and unmanaged code? I am using VS .NET 2003 on Windows XP SP2, with the .NET 1.1 Framework.

    -- Marcus Kwok

    R 1 Reply Last reply
    0
    • R ricecake

      I have a strange problem that has been driving me up the wall. I created a SSCCE that shows my problem. Compile this with cl /EHsc /clr <filename>:

      #using <mscorlib.dll>
      #using <System.dll>
      #using <System.Windows.Forms.dll>

      #include <iostream>

      int main()
      {
      using System::Windows::Forms::DialogResult;
      using System::Windows::Forms::FolderBrowserDialog;
      using System::Windows::Forms::MessageBox;

      double d;
      std::cin >> d;
      
      FolderBrowserDialog\* fb = new FolderBrowserDialog;
      if (fb->ShowDialog() == DialogResult::OK) {
      	MessageBox::Show(fb->SelectedPath);
      }
      

      }

      When I run this program as is, after entering a number on the command line, the FolderBrowserDialog comes up blank. However, if I comment out the std::cin >> d; line, then the FolderBrowserDialog works fine. Does this happen for anybody else? Or am I misusing the mixture of managed and unmanaged code? I am using VS .NET 2003 on Windows XP SP2, with the .NET 1.1 Framework.

      -- Marcus Kwok

      R Offline
      R Offline
      ricecake
      wrote on last edited by
      #2

      OK, I found a solution that seems to work. In the article Mix and Match: Integrate Windows Forms Into Your MFC Applications Through C++ Interop (http://msdn.microsoft.com/msdnmag/issues/06/05/MixAndMatch/[^]), I found this piece of advice:

      If you compile with the /clr option, your code implicitly depends on the multithreaded DLL version of the C runtime libraries (CRT). This means that all files in your project—even those compiled without /clr—must use the multithreaded DLL version of the CRT.

      Adding /MD to the compile command seems to fix it. Incidentally, this also seems to fix my earlier problems (here and here).

      -- Marcus Kwok

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups