I already posted this to the other c/c++ forums here on devshed, but thought that this might be in the "right" place here. Sorry for makeing two posts, but yes..
Im trying to add filenames from a directory to an itembox.
I modified the code @ URL to look like this:
Code:
#include "stdafx.h"
#include <iostream>
#include <io.h>
#include <string>
using namespace std;
void listDir(const char * sdir, int count){
string str, strDir, str1;
struct _finddata_t c_file;
long hFile;
// Find first file in current directory
str = sdir + (string) "\\*";
if( (hFile = _findfirst( str.c_str(), &c_file )) == -1L ){
fprintf(stderr, "Error opening %s!\n", str.c_str());
return;
}
while(_findnext( hFile, &c_file ) == 0)
{
if ((strcmp(c_file.name, ".") == 0 || strcmp(c_file.name, "..") == 0)) {
continue;
}
str1 = c_file.name;
unsigned int loc = str1.find( ".GIF" );
if( loc != string::npos )
{
listBox1->Items->Add(str1);
// cout << str1 << endl;
}
}
_findclose( hFile );
return;
}
First i just made the program to write the filenames on the screen as a console program to see if it only writes .gif files, that worked just fine. I then replace the cout with the listBox1->items->add(str1) so that it would add the filenames to the listbox.
When i try to use it in my c++ .net application i call the function like this:
Code:
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
ListDir(textBox1->Text, 0);
}
Why do i do it like this?. Well i just want to write the directory path into an textbox and when i press the ok button (button1) i made i want the listdir function to pass the textbox1->text as a directory. But the error message i get is this:
Form1.h(112): error C2664: 'DirList::listDir' : cannot convert parameter 1 from 'System::String __gc *' to 'const char *'
I know what it means, but i don't know how to fix it because im new to c++ and .NET, any help would be nice. thanks!