Click here to Skip to main content
15,887,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)

In order to list the filenames from folder:

FileName(BSTR path,BSTR* Retname, LONG* counter)
{
      WIN32_FIND_DATA FindData;
      HANDLE FindHandle = FindFirstFile(path, &FindData);
      BSTR Filelist[1000];
      int i=0;
       
      if (FindHandle  != INVALID_HANDLE_VALUE)
        {
            
           do
            {   
                
                 Filelist[i]= FindData.cFileName;
                *Retname++=Filelist[i];
                ++(*counter);
                   
                                           
            }   while (FindNextFile(FindHandle, &FindData) != 0);
                
                FindClose(FindHandle);
      }

this is the function definition given while creating the component... In the client side :

BSTR *Retname;
BSTR Filelist[1000];
long count = 0;
long *counter ;
counter = &count;
Retname=Filelist;

 hr=pIfiles->FileName(L"C:\\Dynamiclinklibrary\\text\\*.txt",Filelist,&count);

 std::cout<<"Number of files in a folder : " << count << std::endl<< std::endl;



 for(int i =0;i < count ;i++)
  {

      std::cout <<"filenames are: " <<Filelist<< std::endl;
      //Retname++;


  }

while running im getting only the address of the filenames ,im not getting the filenames ..what mistake i ve done..please help..

Posted
Updated 25-Nov-09 22:07pm
v2

The ostream << operator does not know how to decipher a BSTR so it treats it as an int and outputs the addresses that you are seeing. Cast them to a char* (or wchar_t if using UNICODE)
 
Share this answer
 

First of all: format your question! No one will bother to read the question if you just post it as a random mix of text and code. 

Secondly in a COM/ATL question it might be a good idea to also post your *.idl file contents.

And finally looking at your code one thing pops to mind: BSTR should be allocated on the server side and freed on the client side. Look at: SysAllocString and SysFreeString.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900