CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    42

    Question .net to MFC conversion

    Hey I put together this function in .NET and now I need it in MFC. Any help or ideas would be great!

    DirectoryInfo^ dirInfo = gcnew DirectoryInfo(sDir);
    if (dirInfo->Exists) // make sure directory exists
    {
    // Get a reference to each directory in that directory.
    array<FileInfo^>^ files;
    files = dirInfo->GetFiles();

    for (int i = 0; i < files->Length; i++)
    {
    String^ currFileName = files[i]->ToString();
    shortName = fName;
    String^ currFileType = files[i]->Extension;
    DateTime currFileDate = files[i]->CreationTime;
    for (int j = 0; j < 9; j++)
    {
    //Console::WriteLine("j= "+j);
    if (j==0)
    fType=".mpg";
    if (j==1)
    fType=".txt";
    if (j==2)
    fType=".avi";
    if (j==3)
    fType=".divx";
    if (j==4)
    fType=".m1v";
    if (j==5)
    fType=".mov";
    if (j==6)
    fType=".wmv";
    if (j==7)
    fType=".asf";
    if (j==8)
    fType=".mp4";

    if (0 == String::Compare(currFileType, fType, true))
    {
    //test_sw->WriteLine("currFileDate="+currFileDate+" startval="+startVal+" endVal="+endVal);
    if (currFileDate >= startVal && currFileDate <= endVal)
    foundFiles->Add(files[i]);
    }
    }
    }
    array<DirectoryInfo^>^subDirs = dirInfo->GetDirectories();
    for (int i = 0; i < subDirs->Length; i++)
    {
    String^ dirName = subDirs[i]->FullName;
    sDir = dirName;
    FindFile();
    }
    }
    else
    //Console::WriteLine("Does not exist");

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: .net to MFC conversion

    ^ is a pointer (*). gcnew manages all you memory allocations, so you have to do them yourself (new/delete/new[]/delete[]). The rest is a lot of the same. Simply google for the functions you have in .Net and look for the equivalent function in MFC (or ask us )

  3. #3
    Join Date
    Feb 2002
    Posts
    3,788

    Re: .net to MFC conversion


  4. #4
    Join Date
    Jan 2009
    Posts
    42

    Re: .net to MFC conversion

    Quote Originally Posted by Alin View Post
    Hey Alin, that was a great help. I've been running through compiling line by line and its been going great. Until I got to this line.

    strExtension = FileInformation.cFileName;

    This is the error I get:

    error C2679: binary '=' : no operator found which takes a right-hand operand of type 'WCHAR [260]' (or there is no acceptable conversion)
    c:\program files\microsoft visual studio 9.0\vc\include\xstring(914): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>:perator =(const std::basic_string<_Elem,_Traits,_Ax> &)'

    Is there a conversion? A way around this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured