Solved

How to write a LPOLESTR to a text file?

Posted on 2004-04-13
3
1,016 Views
Last Modified: 2012-06-21
I am very new to c++ and need to write a LPOLESTR to a text file.  Is this possible or do I need to convert it to something else?  Also, are there any specific header files I need to accomplish this?  I have already used the funtion StringfromCLSID to convert GUID's to printable strings but apparently they are not writable.  I can't import the fstream class for some reason also so I havn't used that.

This is the code segment -

// Execute the search
    hr = pSearch->ExecuteSearch(    pszSearch,
                                    rgAttributes,
                                    ARRAYSIZE(rgAttributes),
                                    &hSearch);
      cout << "Search Executed: " << hr << endl;
    if(SUCCEEDED(hr))
    {  
        FILE* myOutputFile;
        myOutputFile = fopen("c:\\TestWatch\\ADDeleted.txt", "w");
        // Call IDirectorySearch::GetNextRow() to retrieve the next row of data
        while(S_OK == (hr = pSearch->GetNextRow(hSearch)))
        {
            ADS_SEARCH_COLUMN col;
            UINT i;
           
            // Enumerate the retrieved attributes.
            for(i = 0; i < ARRAYSIZE(rgAttributes); i++)
            {
                hr = pSearch->GetColumn(hSearch, rgAttributes[i], &col);
                if(SUCCEEDED(hr))
                {      
                                                   
          switch(col.dwADsType)
                    {
                        case ADSTYPE_CASE_IGNORE_STRING:
                        case ADSTYPE_DN_STRING:
                        case ADSTYPE_PRINTABLE_STRING:
                        case ADSTYPE_NUMERIC_STRING:
                        case ADSTYPE_OCTET_STRING:
                            wprintf(L"%s: ", rgAttributes[i]);
                            LPOLESTR pStr;
                            for(DWORD x = 0; x < col.dwNumValues; x++)
                            {                                          
                                StringFromCLSID( (REFCLSID)col.pADsValues[x].OctetString.lpValue, &pStr );
                                                      // write to text file hear                                        fput(pStr, myOutputFile);
                                wprintf(L"%s" ,pStr);
                                CoTaskMemFree((LPVOID)pStr );
                                if((x + 1) < col.dwNumValues)
                                {
                                    wprintf(L",");
                                }
                            }
                            wprintf(L"\n");
                            break;
                    }

                    pSearch->FreeColumn(&col);
                }
            }

            wprintf(L"\n");
        }
            fflush(myOutputFile);
            fclose(myOutputFile);
        // Close the search handle to cleanup.
        pSearch->CloseSearchHandle(hSearch);
    }
0
Comment
Question by:misslinda454
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 10814440
An LPOLESTR basically is an UNICODE string. So, all you have to do is using the UNICODE file I/O functions, e.g.

        FILE* myOutputFile;
        myOutputFile = _wfopen(L"c:\\TestWatch\\ADDeleted.txt", L"w");


//...

                                StringFromCLSID( (REFCLSID)col.pADsValues[x].OctetString.lpValue, &pStr );
                                             // write to text file hear
                                    fputws(pStr, myOutputFile);

//...

          fflush(myOutputFile);
          fclose(myOutputFile);
0
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10814461
here's a good article on how to convert OLE strings ....
http://www.devguy.com/fp/Tips/COM/bstr.htm
0
 

Author Comment

by:misslinda454
ID: 10814557
Thanks jkr that worked perfectly!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question