misslinda454
asked on
How to write a LPOLESTR to a text file?
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\\ADDe leted.txt" , "w");
// Call IDirectorySearch::GetNextR ow() to retrieve the next row of data
while(S_OK == (hr = pSearch->GetNextRow(hSearc h)))
{
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 ].OctetStr ing.lpValu e, &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);
}
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\\ADDe
// Call IDirectorySearch::GetNextR
while(S_OK == (hr = pSearch->GetNextRow(hSearc
{
ADS_SEARCH_COLUMN col;
UINT i;
// Enumerate the retrieved attributes.
for(i = 0; i < ARRAYSIZE(rgAttributes); i++)
{
hr = pSearch->GetColumn(hSearch
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
// 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
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks jkr that worked perfectly!
http://www.devguy.com/fp/Tips/COM/bstr.htm