Convert BSTR to Const char*
-
Hi all.. As i am new c# .net......I have created a structure in Dll and calling that DLL in vc++ console Application.... I am getting the structure variable in my console application... when i put printf..I am able to see the values.. but when i save it in a text file i am getting buffer value .. Actually i am trying with code..
const _TCHAR *elementName[100]; const _TCHAR *elementValue[100]; Sharepoint_API::StructGetSite HUGEP *pBSTR; hr = SafeArrayAccessData(pICalc->GetData, (void HUGEP* FAR*)&pBSTR); for(i=0; i<pBSTR[0].totAttribute; i++){ elementName [i] = "NAME"; elementValue[i] = (LPCTSTR)pBSTR[i].Atrribute; printf("%d. is %S \n", i+1, elementValue[i]); ofstream TestFile("E:\\Test.txt",ios::app); if(TestFile) { TestFile<<elementValue[i];//"dd";//elementValue[i]; } else if(!TestFile) { } TestFile.close();
In printf I am getting the correct value... but in text file i am getting "h" pBSTR[0].totAttribute is the total count i am getting from structure from dll thank you....very much.. manjuHi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
-
Hi all.. As i am new c# .net......I have created a structure in Dll and calling that DLL in vc++ console Application.... I am getting the structure variable in my console application... when i put printf..I am able to see the values.. but when i save it in a text file i am getting buffer value .. Actually i am trying with code..
const _TCHAR *elementName[100]; const _TCHAR *elementValue[100]; Sharepoint_API::StructGetSite HUGEP *pBSTR; hr = SafeArrayAccessData(pICalc->GetData, (void HUGEP* FAR*)&pBSTR); for(i=0; i<pBSTR[0].totAttribute; i++){ elementName [i] = "NAME"; elementValue[i] = (LPCTSTR)pBSTR[i].Atrribute; printf("%d. is %S \n", i+1, elementValue[i]); ofstream TestFile("E:\\Test.txt",ios::app); if(TestFile) { TestFile<<elementValue[i];//"dd";//elementValue[i]; } else if(!TestFile) { } TestFile.close();
In printf I am getting the correct value... but in text file i am getting "h" pBSTR[0].totAttribute is the total count i am getting from structure from dll thank you....very much.. manjuHi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
Probably you've to replace
TestFile << elementValue[i];
with
TestFile.write( (const char*) elementValue[i], _tcslen(elementValue[i])*sizeof(TCHAR));
since even a
wostream
would not do the trick. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Probably you've to replace
TestFile << elementValue[i];
with
TestFile.write( (const char*) elementValue[i], _tcslen(elementValue[i])*sizeof(TCHAR));
since even a
wostream
would not do the trick. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Sorry sir... not working.. yet the same result.. I am getting output as hhhhh
Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
What's the input, instead?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
What's the input, instead?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]CPallini wrote:
What's the input, instead?
Actually i will get the sharepoint folders which are stored in structures in the dll... Actually i must get ///////////////////////////// http://sharepoint/Docs http://sharepoint/News http://sharepoint/Reports http://sharepoint/SearchCenter http://sharepoint/SiteDirectory ///////////////////////////// when i put printf i.e printf("%d. is %S \n", i+1, elementValue[i]); I am getting the value for elementValue[i]
Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
-
Hi all.. As i am new c# .net......I have created a structure in Dll and calling that DLL in vc++ console Application.... I am getting the structure variable in my console application... when i put printf..I am able to see the values.. but when i save it in a text file i am getting buffer value .. Actually i am trying with code..
const _TCHAR *elementName[100]; const _TCHAR *elementValue[100]; Sharepoint_API::StructGetSite HUGEP *pBSTR; hr = SafeArrayAccessData(pICalc->GetData, (void HUGEP* FAR*)&pBSTR); for(i=0; i<pBSTR[0].totAttribute; i++){ elementName [i] = "NAME"; elementValue[i] = (LPCTSTR)pBSTR[i].Atrribute; printf("%d. is %S \n", i+1, elementValue[i]); ofstream TestFile("E:\\Test.txt",ios::app); if(TestFile) { TestFile<<elementValue[i];//"dd";//elementValue[i]; } else if(!TestFile) { } TestFile.close();
In printf I am getting the correct value... but in text file i am getting "h" pBSTR[0].totAttribute is the total count i am getting from structure from dll thank you....very much.. manjuHi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
manju#123 wrote:
ofstream TestFile("E:\\Test.txt",ios::app);
Since your writing a wide char text, either you have to use
wofstream
instead ofofstream
or Covert the elementValue[i] to mutibyte usingsprintf()
orWideCharToMultiByte()
before writing..manju#123 wrote:
I am Mnaju
Correct your signature :)
nave [OpenedFileFinder]
-
CPallini wrote:
What's the input, instead?
Actually i will get the sharepoint folders which are stored in structures in the dll... Actually i must get ///////////////////////////// http://sharepoint/Docs http://sharepoint/News http://sharepoint/Reports http://sharepoint/SearchCenter http://sharepoint/SiteDirectory ///////////////////////////// when i put printf i.e printf("%d. is %S \n", i+1, elementValue[i]); I am getting the value for elementValue[i]
Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
If you need to write a UNICODE file the code I provided works fine but you have to put the proper
BOM
at the very start of the file, for instanceTCHAR * szIn = _T("http://sharepoint/Docs");
ofstream of("foo.txt", ios::out);
#ifdef _UNICODE
TCHAR BOM = 0xFEFF;
of.write((const char *) &BOM, sizeof(TCHAR));
#endif
of.write((const char *) szIn, _tcslen(szIn)* sizeof(TCHAR));
of.close();On the other hand, if you need to write a
ANSI
file then follow Naveen suggestion: usewofstream
instead of ofstream.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
manju#123 wrote:
ofstream TestFile("E:\\Test.txt",ios::app);
Since your writing a wide char text, either you have to use
wofstream
instead ofofstream
or Covert the elementValue[i] to mutibyte usingsprintf()
orWideCharToMultiByte()
before writing..manju#123 wrote:
I am Mnaju
Correct your signature :)
nave [OpenedFileFinder]
Naveen wrote:
manju#123 wrote: I am Mnaju Correct your signature [Smile] nave [OpenedFileFinder]
Also '
lokking
' should be fixed in the signature. :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Naveen wrote:
manju#123 wrote: I am Mnaju Correct your signature [Smile] nave [OpenedFileFinder]
Also '
lokking
' should be fixed in the signature. :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]ops. I didn't notice :laugh:
nave [OpenedFileFinder]
-
If you need to write a UNICODE file the code I provided works fine but you have to put the proper
BOM
at the very start of the file, for instanceTCHAR * szIn = _T("http://sharepoint/Docs");
ofstream of("foo.txt", ios::out);
#ifdef _UNICODE
TCHAR BOM = 0xFEFF;
of.write((const char *) &BOM, sizeof(TCHAR));
#endif
of.write((const char *) szIn, _tcslen(szIn)* sizeof(TCHAR));
of.close();On the other hand, if you need to write a
ANSI
file then follow Naveen suggestion: usewofstream
instead of ofstream.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Please leave us our small pleasures, they are small, but they are ours! - Mycroft Holmes ^ .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
-
Please leave us our small pleasures, they are small, but they are ours! - Mycroft Holmes ^ .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
Rajesh R Subramanian wrote:
[Suspicious]
:confused:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Rajesh R Subramanian wrote:
[Suspicious]
:confused:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Hint: That's just not an emoticon, it is a hyperlink, in my previous post. A post of mine is downvoted for no good reason (IMHO) in that thread. So, superhero intervention needed.
Please leave us our small pleasures, they are small, but they are ours! - Mycroft Holmes ^ .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
-
Hint: That's just not an emoticon, it is a hyperlink, in my previous post. A post of mine is downvoted for no good reason (IMHO) in that thread. So, superhero intervention needed.
Please leave us our small pleasures, they are small, but they are ours! - Mycroft Holmes ^ .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
Rajesh R Subramanian wrote:
That's just not an emoticon, it is a hyperlink, in my previous post.
OMG: I'm Mr.Dumb (drugz, maybe?). :-D BTW: balanced. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Rajesh R Subramanian wrote:
That's just not an emoticon, it is a hyperlink, in my previous post.
OMG: I'm Mr.Dumb (drugz, maybe?). :-D BTW: balanced. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]CPallini wrote:
BTW: balanced.
Thanks, Mr.Dumb. :-D :laugh:
Please leave us our small pleasures, they are small, but they are ours! - Mycroft Holmes ^ .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]