|
|
|
the std::string class has a c_str() function which returns a char*...
std::string str = "Hello World";
char psz[20] = {0};
::strcpy(str.c_str(), psz);
|
|
|
|
|
so you think deleting your previous post and reposting it exactly the same again will change something ?
just wondering : why are you insisting that much about the CLR thing ?
you want what exactly ?
convert a C++ string (std::string) to a C style string (char*) ?
or you want to get the HDD serial number anyway ?
BTW, where are you taking this function from ?
|
|
|
|
|
toxcct wrote: just wondering : why are you insisting that much about the CLR thing ?
Maybe because searching MSDN for string returns tons of System.String links but almost no std::string links.
MS is pushing us heavily in the direction of .NET.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
hum, yes, probably, but i don't read the MSDN, i just KNOW it ! lol
|
|
|
|
|
I want to convert a char array containing embedded NULL(/0) chars to BSTR.
eg cArr['1','2','NULL','3','NULL','4','5','NULL'].
Is it possible to convert it to bstr without losing anything.
So the _bstr_t variable will contain "12NULL3NULL45NULL"
|
|
|
|
|
This [^] looks promising.
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
|
|
|
|
|
You are correct, Seems to work:
BSTR MyBstr = ::SysAllocStringByteLen(strVar, strSize);
_bstr_t bstrSend(MyBstr, true);
|
|
|
|
|
vsingh123 wrote: You are correct
Of course.
(just kidding... )
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
|
|
|
|
|
vsingh123 wrote: I want to convert a char array containing embedded NULL(/0) chars to BSTR.
eg cArr['1','2','NULL','3','NULL','4','5','NULL'].
But your string does not contain such. Perhaps you meant something like:
char cArr[] = { '1', '2', '\0', '3', '\0', '4', '5', '\0' };
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I want to get the pixel width and height of a string for a particular font.
I have searched the MSDN and i found the function below
public:
SizeF MeasureString(
String^ text,
Font^ font
}
How can i use this function in my VC++ 2005 MFC project?
I have tried to use System::Drawing but failed.
|
|
|
|
|
It seems that your question is depends to Managed C++/CLI forum. 
|
|
|
|
|
The code you found (as Hamid pointed out) is for managed c++ code, and would be best in the CLI forum.
You message seems to be confused between .net, and mfc. System::Drawing is not in any way related to MFC.
Assuming you're doing MFC, you can select the font into a DC, and use GetTextExtentEx to get dimensions of a string using that font.
You need to specify text, as "i" is usually narrower than "W".
Iain.
Iain Clarke appears because CPallini still cares.
|
|
|
|
|
I have a ListCtrl with a set of CTime:
09.45.25
10.44.22
07.49.25
I need to sort these..
also fyi.. i already have a array consisting of these values in m_arrTimes
Have used:
void CEntryDlg::OnColumnClickItemsList(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
m_bSortNameAscSpItem = !m_bSortNameAscSpItem;<br />
<br />
SortingItemsList();<br />
<br />
*pResult = 0;<br />
}<br />
<br />
void CEntryDlg::SortingItemsList()<br />
{<br />
m_ctrlTimesList.SortItems(CEntryDlg::CompareSpItem, (DWORD)reinterpret_cast<DWORD>(this));<br />
<br />
for(int i = 0; i < m_ctrlTimesList.GetItemCount(); i++)<br />
{<br />
m_ctrlTimesList.SetItemData(i, (LPARAM)i);<br />
}<br />
}<br />
<br />
int CALLBACK CEntryDlg::CompareSpItem(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)<br />
{<br />
CEntryDlg*pCurrentObj = (CEntryDlg*) lParamSort;<br />
<br />
CString strTemp1 = pCurrentObj->m_ctrlTimesList.GetItemText(lParam1, 0); <br />
CString strTemp2 = pCurrentObj->m_ctrlTimesList.GetItemText(lParam2, 0); <br />
<br />
CString strHr1,strMn1,strSc1;<br />
strHr1 = strTemp1.Mid(0,2);<br />
strMn1 = strTemp1.Mid(3,2);<br />
strSc1 = strTemp1.Mid(6);<br />
<br />
CString strHr2,strMn2,strSc2;<br />
strHr2 = strTemp2.Mid(0,2);<br />
strMn2 = strTemp2.Mid(3,2);<br />
strSc2 = strTemp2.Mid(6);<br />
<br />
CTime time1(2000,1,1, GetIntFromString(strHr1), GetIntFromString(strMn1),GetIntFromString(strSc1));<br />
CTime time2(2000,1,1, GetIntFromString(strHr2), GetIntFromString(strMn2),GetIntFromString(strSc2));<br />
<br />
if(pCurrentObj->m_bSortNameAscSpItem)<br />
{<br />
if(time1 == time2)<br />
return 0;<br />
else if(time1 < time2)<br />
return -1;<br />
else if (time1 > time2)<br />
return 1;<br />
}<br />
else<br />
{<br />
if(time2 == time1)<br />
return 0;<br />
else if(time2 < time1)<br />
return -1;<br />
else if (time2 > time1)<br />
return 1;<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
CEntryDlg::GetIntFromString(CString str){<br />
LPTSTR lpsz = new TCHAR[str.GetLength()+1];<br />
int val=0;<br />
if(lpsz !=NULL)<br />
{<br />
_tcscpy(lpsz, str);<br />
val=::atoi(lpsz);<br />
delete[] lpsz;<br />
}<br />
return(val);<br />
}<br />
<br />
none of there seem to sort correctly..
Priya Sundar
modified on Wednesday, April 16, 2008 8:39 AM
|
|
|
|
|
I don't know what you are trying to do here (there a lot of missing information to understand your problem and your code). Anyway, if you need to sort CTime objects, you can use the comparison operators[^], that will probably be much better then trying to do it yourself.
|
|
|
|
|
thanks.. have implemented that. Still it is not sorting correctly.
Also modified the thread with additional information.
Priya Sundar
|
|
|
|
|
By googling a bit (yeah, you can do that too you know ), I found this article[^]. Check also the comments.
And this behavior was in fact explained in the documentation[^].
EDIT: by the way, I don't think the solution provided in the article is the correct way to go, but I posted it so that you can see where your problem is. Check some of the comments and you'll find better way to manage it.
|
|
|
|
|
Hai Cedric,
Actually that article and the links in the article really helped a lot.
And i solved my problem as said in the article - "The function CListCtrl::SortItems(...) is only usefull if we store a pointer in the 32-bit associated value and we want to sort the items by some value that comes from that pointer. "
And I too first google, if i still didnt find the solution, then i post it as a thread.
Then i guess in this case it might help if you suggest me the keywords you used to search this article. That will be a lot of help in future.
Thanks once again!
Priya Sundar
|
|
|
|
|
I just used CListCtrl and SortItems. I think I searched on codeproject too (that's why I found the article). So, if you have a problem, you can google for it and search on the CP articles (there is a lot of good stuff here you know ).
|
|
|
|
|
|
Don't forget the developer's best friend: your debugger. Using it in that situation would immediately reveal that there's something wrong with the parameters that are passed to your callback function.
|
|
|
|
|
Hello All,
I am trying to insert a BMP image in to picture control.
I have added Microsoft common dialog control Ver6 ActiveX control.
IDC_COMMONDIALOG1 Type :- CcommonDialog1 Member:- m_com
Picture Control:-
IDC_STATIC1 Type :- CStatic Member:- m_st1
I have show button in the dialog, when the we click on that we can select a BMP file and show the same file in the Picture control in the dialog.for that i have used the below code.
void CImageAppDlg::OnShow() <br />
{<br />
<br />
<br />
<br />
CString file;<br />
file.Empty();<br />
m_com.ShowOpen();<br />
file=m_com.GetFileName();<br />
file.TrimRight();<br />
<br />
<br />
if(m_hBmpNew != NULL )<br />
DeleteObject(m_hBmpNew);<br />
sourcex=sourcey=0;
if(file.IsEmpty())<br />
AfxMessageBox("Please Select a picture file");<br />
else{<br />
if(file.Right(3)!="bmp")<br />
AfxMessageBox("Please Select a .bmp file");<br />
else<br />
{<br />
m_hBmpNew = (HBITMAP) LoadImage(<br />
AfxGetInstanceHandle(), <br />
file, <br />
IMAGE_BITMAP, <br />
0, <br />
0, <br />
LR_LOADFROMFILE); <br />
if( m_hBmpNew == NULL ){<br />
AfxMessageBox("Load Image Failed");}<br />
<br />
else{<br />
m_st1.GetClientRect( &rectStaticClient );<br />
rectStaticClient.NormalizeRect();<br />
m_size.cx=rectStaticClient.Size().cx;<br />
m_size.cy=rectStaticClient.Size().cy;<br />
m_size.cx = rectStaticClient.Width();
m_size.cy = rectStaticClient.Height();
<br />
<br />
m_st1.ClientToScreen( &rectStaticClient );<br />
ScreenToClient( &rectStaticClient);<br />
<br />
m_pt.x = rectStaticClient.left;<br />
m_pt.y = rectStaticClient.top;<br />
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );<br />
VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) );<br />
<br />
offsetx= m_pt.x;<br />
offsety=m_pt.y;<br />
if(m_bmInfo.bmWidth<=m_size.cx)<br />
{<br />
if((m_size.cx-m_bmInfo.bmWidth)==0)<br />
offsetx= m_pt.x;<br />
else<br />
offsetx= m_pt.x+((m_size.cx-m_bmInfo.bmWidth)/2);<br />
<br />
}<br />
else<br />
if(m_bmInfo.bmHeight<=m_size.cy)<br />
{<br />
if((m_size.cy-m_bmInfo.bmHeight)==0)<br />
offsety= m_pt.y;<br />
else<br />
offsety= m_pt.y+((m_size.cy-m_bmInfo.bmHeight)/2);<br />
}<br />
else<br />
<br />
InvalidateRect(&rectStaticClient);<br />
}<br />
}<br />
}<br />
<br />
}<br />
code has no errors but in the run time i am getting this error
Microsoft VC++ Debug Library
Debug Assertion Failed Error
Can u please tell me what is cause for the error ??
Thanking you ...
Pruthvi R.
|
|
|
|
|
You can use of LoadImage for load your bmp file or CImage class for other foramats and then use of SetBitmap(HBITMAP).
|
|
|
|
|
Hi Hamid,
Thanks for the response.
I have used the LoadImage function only, but still i am getting the run time error. can u please tell me what is the cause.. ?
|
|
|
|
|