Jump to content
  • Advertisement
Sign in to follow this  
PyroBlizzard

DirectoryInfo [C++]

This topic is 4822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so im trying to create a function to use this feature, however for some reason, even the MSDN documented example provides an error to me. Here is the specific line that brings the first error
Quote:
DirectoryInfo* di1 = new DirectoryInfo(S".");
Which produces
Quote:
Form1.cpp(53) : error C2065: 'DirectoryInfo' : undeclared identifier
Thoughts?

Share this post


Link to post
Share on other sites
Advertisement
First of all, are you making a Managed program? Because DirectoryInfo is a part of the .Net framework. Secondly: Showing us that little piece of code tells us nothing really, although, you would be better off using C++/CLI.

Share this post


Link to post
Share on other sites
I am using managed C++

Quote:

#include "stdafx.h"
#include "Form1.h"
#include <windows.h>

#using <mscorlib.dll>

using namespace WarMiner;
using namespace System;
using namespace Microsoft::Win32;

#undef MessageBox

System::String* RetrieveKeys()
{
//Create handlers for RegistryKey
RegistryKey* localMachine = Registry::LocalMachine;
if (!(localMachine->OpenSubKey("SOFTWARE\\Blizzard Entertainment\\World of Warcraft")))
{
//Exception:: Could not find registry key
System::String* directory = "Could not detect WoW folder";
return directory;
}
else
{
//Registry key found, value returned
RegistryKey* software = localMachine->OpenSubKey("SOFTWARE\\Blizzard Entertainment\\World of Warcraft");
System::String* directory = software->GetValue("InstallPath")->ToString();
return directory;
}
}

void dirInfo()
{
}

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//variables
System::String* directory;

//Creating a new form instance of fWarMiner
Form1* mainForm = new Form1();

//Grabbing registry value for World of Warcraft Directory
directory = RetrieveKeys();

//Sets textbox value to World of Warcraft directory
mainForm->tWoWDir->Text = directory;

DirectoryInfo* di1 = new DirectoryInfo(S".");
//dirInfo();

// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualstyles();

System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
Application::Run(mainForm);
return 0;
}

Share this post


Link to post
Share on other sites
figured it out, I was missing a

Quote:
using namespace System::IO;


But, now I have an issue. My function works, and returns an array

Quote:
System::Array* dirInfo(System::String* directory)
{
DirectoryInfo* dirInfo = new DirectoryInfo(directory);
if (!(dirInfo->Exists))
{
return 0;
}
else
{
DirectoryInfo* subDirs[] = dirInfo->GetDirectories(S"");
return subDirs;
}


}


But when I try to use the array to fill a combo box

Quote:
//Grabbing subfolders of World of Warcraft directory
subDirs = dirInfo(directory);

//Adds subfolders into cPlayerAccounts
for (int i = 0; i < subDirs->Length; i++)
{
System::String* dirName = subDirs->ToString();
mainForm->cPlayerAccounts->Items->Add(dirName);
}


It returns an error

Quote:
Form1.cpp(73) : error C2845: '[' : cannot perform pointer arithmetic on __gc pointer 'System::Array __gc *'
Form1.cpp(73) : error C2227: left of '->ToString' must point to class/struct/union

Share this post


Link to post
Share on other sites
Ok, I've narrowed it down to somewhere being in this function, and its return of the array

Quote:
System::Array* dirInfo(System::String* directory)[]
{
DirectoryInfo* dirInfo = new DirectoryInfo(directory);
if (dirInfo->Exists)
{
DirectoryInfo* subDirs[] = dirInfo->GetDirectories();
return subDirs;
}
}


And the function call
Quote:
System::Array* subDirs = dirInfo(directory);


For some reason, it doesnt actually seem to be returning an array. Any thoughts?

Share this post


Link to post
Share on other sites
Im not too familiar with .NET, but isnt the return type
DirectoryInfo* [] ?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiodirectoryinfoclassgetdirectoriestopic1.asp

Share this post


Link to post
Share on other sites
haha, yea, I had just figured that out. I never had thought about actually using a return of DirectoryInfo*. I didnt think that was possible. Just shows how much of a noob I really am, neh. ^^;;;;

Now a new issue. Im trying to take my current directory, and append a folder name to the end of it. I think I should use the Join function, but the second parameter asks for an array, and I dont really see how or why. Any other thoughts?

EDIT: Nevermind, figured it out. String::Concat

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!