Connecting Tech Pros Worldwide Forums | Help | Site Map

BSTR problem

Newbie
 
Join Date: Feb 2007
Location: Syracuse
Posts: 18
#1: Mar 24 '07
Hi all,

I'm using a BSTR as an out parameter in a function which reads a file. Here is my code.

HRESULT __stdcall CA::getFile(BSTR bstr,BSTR *fileCont)
{
if (!fileCont)
return E_POINTER;
wstring str;
char sz_path[255];
wifstream inFile;
size_t bufsize;
wchar_t* path=bstr;
std::wstring _temp;

bufsize = wcstombs(sz_path,path,255);
if(bufsize==sizeof(sz_path) || bufsize==-1)
{
return S_FALSE;
}
inFile.open(sz_path);
if(!inFile.is_open())
return S_FALSE;
while(!inFile.eof())
{
inFile >> str;
}

*fileCont = SysAllocString(OLESTR(str));

return S_OK;
}

I'm getting errors in the statement SysAllocString(OLESTR(str)).

Please correct my syntax.

Thanks a lot.

SC

Reply