|
amitmistry_petlad wrote: DWORD
What DWORD?
If you mean values read from the xml-file, you can convert them from textual format into DWORDs by calling ::wcstol() .
I'm just guessing that the above is your problem. If it's not, describe it further.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
i think you might forget the previous code so ,
look i explain with detail code .
WCHAR szBuff[5000]={}; // which i have declare global
//below is my function which used the gelobal variable szBuff read data from file
void _FilePersistandata()
{
HANDLE hFile;
DWORD dwFileSize, dwHighSize, dwBytesRead ;
DWORD dwRecvLen = 0;
hFile=CreateFile ( L"c:\\FileProperty.XML"
, GENERIC_READ | GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
if(hFile == INVALID_HANDLE_VALUE)
{
MessageBox(0,_T("File is not created"),_T("Create File"),0);
}
else
{
MessageBox(0,_T("File is created"),_T("Create File"),0);
}
bool bSucced=ReadFile(hFile,<big>&szBuff</big>,5000,&dwRecvLen,NULL);
szBuff[dwRecvLen] = '\0';
<code>
std::string source(szBuff);
</code>
WCHAR w_Out[MAX_PATH];
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,source.c_str(),(int)(source.length() + 1),w_Out,MAX_PATH);
MessageBox(0,LPCWSTR(w_Out),L"Message",0);
}
let me know if something is wrong here ,then i'll change it.
amit
|
|
|
|
|
Instead of making assumptions about my memory, you should get your datatypes straight.
The things you claim to be DWORD is never DWORD in the code you've posted.
You declare szBuff as an array of WCHAR and WCHAR is a typedef that can be either 8 or 16 bits wide, but never 32 as a DWORD . In your configuration it's 16 bits wide since you've enabled support for unicode.
The only thing about szBuff that is 32 bits wide is its address you provide as argument in the call to ReadFile , but do not mix up an address with a 32 bit integer value.
ReadFile read the contents of a file in raw format, i.e. byte-wise, and puts it at a memory location you provide as argument, szBuff in your case. If the format of the data read doesn't fit your needs, convert it! In this case by calling MultiByteToWideChar providing the buffer with the data read as input and a pointer to a new location where you want the resulting data to be stored.
Bring up the memory debug window and have a look at your <codes>zBuff. After a successful call to ReadFile you will see the contents of your file there.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
|
hello friends
char ch[10];
Cstring str ="Rahul"
memset(ch,0,10);///set ch to '\0';
memcpy(ch,str,5);
plz tell me where ch will be stored..on heap or on stack..thanks
Born To Code
|
|
|
|
|
as you don't allocate it with a new, it will be in the stack...
|
|
|
|
|
Both of your variables will be located on the stack. Even the 10 bytes referred to by ch will be located on the stack.
To use the heap you have to allocate memory by calling new in C++ or malloc or similar in C and you always get a pointer in return to be able to refer to the allocated memory.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
rahul.shendurnikar wrote: char ch[10];
CString str ="Rahul"
Both of those allocate the specified objects on the stack - that is, the array of char and the CString object will be allocated on the stack.
However, note the memory used by the CString object will be allocated on the heap, because that is how CString s work. In other words, you are causing two kinds of allocations when really only one is required. Oh, and since heap allocation operations can raise exceptions, you should be assigning to that string object in a try/catch block just to be safe!
Note that you are getting really lucky by using memcpy to copy into the string object's buffer - that is generally not the correct way to get data into or out of a real object.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
James R. Twine wrote: Note that you are getting really lucky by using memcpy to copy into the string object's buffer - that is generally not the correct way to get data into or out of a real object.
Where is he doing that?
|
|
|
|
|
You are correct - he is copying out of it, but only by the grace of CString::operator LPCTSTR() . My warnings still stand, though.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
heh I just noticed it was memcpy .
I was thinking hmm I thought that's what the LPCTSTR() operator was FOR!
Never mind
|
|
|
|
|
Hi everybody,
in my application i have a GridCtrl on a View.
If the Grid has the focus and i hit a Key, the OnKeyDown Event of the GridCtrl responses.
All nice ...
But if i hit the Escape Key, this stroke will not be catched in the GridCtrl.
Also the F6-Key.
Is there a special thing that i don't know?
Big thanks
|
|
|
|
|
In a text box. you need to override the OnGetDlgCode function as shown to get all keys.
UINT CEdit_Numeric::OnGetDlgCode()
{
return( CEdit::OnGetDlgCode() | DLGC_WANTALLKEYS );
}
Then you can get the keys with
void CEdit_Numeric::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_RETURN:
.................
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
maybe its the same with a grid control
|
|
|
|
|
Big thanks !
It resolves the problem behind this problem LOL
|
|
|
|
|
Hi,
I am doing some GUI dialogs in MFC. The problem goes like this:
I have a parent dialog which can create a modeless child "keyboard" dialog,with some special prescribed keys. The user is suppose to click on keys on the "keyboard" dialog and the input is suppose to appear on an Edit box on the parent dialog. The issue is that I want the user to have the freedom of using both the physical keyboard and the "Keyboard" dialog. So, I tried to use SetFocus() onto the Parent's Edit box after hitting keys on the "Keyboard" dialog.
The problem is that the after SetFocus() is issued, the blinking text cursor is always at the beginng left end of the Edit box regardless of whether there is any text in the edit box. This poses a problem when the user changes to using the physical keyboard since text will be input at the beginning of the current text rather than from the end of the text in the Edit box.
So my question is how do I set the position of the blinking text cursor to the end of the text after SetFocus()? Thanks alot!
|
|
|
|
|
What about CWnd::SetCaretPos ?
|
|
|
|
|
That may cause a visual indication, but the underlying edit control will maintain its last insertion point.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks for the sugestion. At least I now know that blinking cursor is called a caret.
|
|
|
|
|
You could do this:
CEdit *pEdit = static_cast<CEdit *>( GetDlgItem( IDC_THE_EDIT_BOX ) );
int iLength = pEdit->GetWindowTextLength();
pEdit->SetSel( iLength, iLength );
|
|
|
|
|
This is indeed a great method! works nice n sweet. Thanks.
|
|
|
|
|
The SetSel(...) solution is the best, IMHO, although I question the habit of casting the return of CWnd::GetDlgItem(...) unless you really know what you are doing...
You should investigate the MA_NOACTIVATE return value from processing the WM_MOUSEACTIVATE message. I believe that is how you can get an on-screen keyboard to not cause kill focus events to be sent to another window when it is is being used. You may have to rely on mouse position as opposed to button click events if you do this.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks for your input. the SetSel method has worked well for me. Dint investigate the WM_MOUSEACTIVATE method as using mouse position may complicated matters for me. anyway, thanks!;)
|
|
|
|
|
Hi All,
I have a little doubt about templates, and no compiler to test this.
Is it possible to have a template member function in a class that is not template, or even a global template function ??
i'm puzzling as i just thought to this...
thanks for your answers guyz
|
|
|
|
|
yes
never say die
|
|
|
|
|
that's a very pragmatic answer, but thanks ! lol
|
|
|
|