|
Eranga Thennakoon wrote: ...after reading the first 24 characters, where the operator LPCTSTR() points to...
_tcsncpy() does not change anything within the CString object. The second argument is the address from which to start copying.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for all,
Actually I've come across with a new requirement and now my data in a char buffer. I want to read a fixed amount, actually the in to char fixBuffer[24]; , from the larger buffer. Can you give some clue on it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Hello everyone,
I am using Visual Studio 2005 and I am wondering whether we could debug into the global delete operator?
I have tried to debug by setting a break point to delete statement, but I could only debug into destructor.
My understanding is, when we call delete, the internal operations are,
1. invoking destructor;
2. invoking global delete operator.
Is my understanding correct?
For example,
<br />
class Foo {<br />
<br />
int i;<br />
<br />
public:<br />
<br />
Foo()<br />
{<br />
i = 100;<br />
}<br />
<br />
~Foo()<br />
{<br />
i = 0;<br />
}<br />
};<br />
<br />
int main (int argc, char** argv)<br />
{<br />
Foo* f = new Foo();<br />
<br />
delete f;
<br />
return 0;<br />
}<br />
thanks in advance,
George
|
|
|
|
|
why don't you just place a break point in the destructor of the object?
|
|
|
|
|
Thanks Haroon,
I can debug into the destructor, but can not debug into global delete operator.
regards,
George
|
|
|
|
|
hmmm...actually its debugging into it fine on my end (in VS2003)...
|
|
|
|
|
Hi Haroon,
You mean you can debug into the global delete operator in Visual Studio 2003 from delete <pointer> statement? I am using Visual Studio 2005.
regards,
George
|
|
|
|
|
It's a little more complex than that, at least in a Debug build which is where you'll most likely be debugging. In order to debug into delete properly you need to have installed the CRuntime Source files when you installed Visual Studio ( They can probably be added afterwards form the CD ) and then you need to include their folder in the source paths for your project so the debugger can find the source.
delete is potentially a long and complex process depending on what you're deleting and even with all the source not every stage will be visible. Remember the compiler generates destructors for classes where you don't write one and these will get called but throw you into the disassembler because there is no source just injected machine language. Don't let this put you off.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks Matthew,
Through my study, I find the global delete operator is defined in dbgdel.cpp, and I have the source codes. I have tried to add it to the source folders by Source Files --> Add --> Existing Item, but in this approach, it will bring me more and more dependencies' error (e.g. can not find .h or something) when I build all the files (including deldbg.cpp) in my project. So I think it may be not the correct way to add the source to my project. Could you help to indicate in my situation what is the most appropriate way to add the source to my project please?
regards,
George
|
|
|
|
|
I am trying to write event macros for excel in vb editor but it works when the excel is open but when i close and reopen the excel it does not work. can any one let me know what wrong i am doing in excel
S.Yamini
|
|
|
|
|
Where's the C++ question?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Hi, I'm wondering which of these is more efficient in C code:
Let's say I have a function:
int check(int x)<br />
{<br />
int var;<br />
<br />
var = calc_var(x);<br />
<br />
return var;<br />
}
Is it more efficient to make that "int var;" into "static int var;" or is it better to keep it as non-static? This is a single-threaded program and the "calc_var" function always returns a value so changing var to static will have exactly the same programmatic behavior, I'm just wondering which is actually a more efficient way to do it, since this "check(int x)" function is called all over the place constantly, sometimes hundreds of times per second.
Thanks!
KR
|
|
|
|
|
In my humble opinion negligible change in efficiency. The way to get more efficient code in that case is to do this
__inline int check(int x) { return calc_var(x); }
provided the compiler complies with the __inline hint it will remove "sometimes hundreds of times per second" of constructing and releasing a stackframe around the unnecessary function call.
Or even, at the risk of incurring the wrath of some of the other members here
#define check(x) calc_var(x)
which will guarantee the unnecessary function call and stackframe are eliminated
|
|
|
|
|
int check(int x)
{
return calc_var(x);
}
would be better as the int is only copied once. If you need the value of calc_var() for further processing in check() I'd avoid a static as you will probably end up confusing the optimiser and wind up with worse machine code. In my limited experiance spending time on questions like this is often a waste of time.
|
|
|
|
|
Sorry, I was sort of unclear with my question; the check function I posted is a simplistic example, the real function is about 600 lines long and is a lot more complex than just returning another function, so it's not as easy as just eliminating a variable declaration.
KR
|
|
|
|
|
A local variable is likely in the cache, so it is more effiecint.
A static one may be far from the current instruction.
|
|
|
|
|
|
KellyR wrote: Is it more efficient ...
You can only find that out by testing. Testing with real data, that is.
And before you spend time for this, you should really be sure that this function call is a bottleneck of your application.
So - profile it! While processing real data!
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"
|
|
|
|
|
I want to put it at the top part of client for the customer to pick up thumbnail to the client. Like this:
/-------------------------------------------------------\
| /--------------------------------------------------\ |
| |:laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh::laugh:| |
| |--------------------------------------------------| |
| |
| |
| |
\-------------------------------------------------------/
|
|
|
|
|
Do you want to have thumbnails of images on the listctrl of left to right?
|
|
|
|
|
|
On the Listctrl you have a option its name is Alignment you can set it to top or left.
|
|
|
|
|
Hi,
I am converting my MFC project from a dialog-based application to a single document interface. My dialog box contains a button which calls DoModal() on a Server-site dialog written by our company. Normally, this would bring up a window showing all of the services available on a server. This works fine and dandy in my dialog-based version of the project; however, in my new SDI application (in which the main dialog window from the first project fills the child view), calling DoModal() no longer brings up another window. I tried putting DoModal() code for both the server-site dialog and some of my own process status threads all over the project (inside the main dialog class, inside the child view class, and inside the application class), and nothing works. The only modal dialog I can bring up in the entire project is the about box which was already pre-coded. If anyone has any clue as to why DoModal() fails in my SDI application, please let me know.
|
|
|
|
|
Can you put a bit of code, about how are you doing that?
If you are in MFC (I guess with wizard, because of the About.. box) it should be easy to do. The easiest way is to make the dialog in the resource editor, then create a class to that dialog and then make the call like:
OnButtonClick ()
{
CMyDialog newDlg;
if (IDCANCEL == newDlg.DoModal ())
{
return;
}
return;
}
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I am writing exactly what you put, yet it does not bring up a modal dialog box. If I debug, I can step into the DoModal() function to see what's wrong, and it looks like it fails when checking if lpDialogTemplate is NULL:
<br />
INT_PTR CDialog::DoModal()<br />
{<br />
ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||<br />
m_lpDialogTemplate != NULL);<br />
<br />
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;<br />
HGLOBAL hDialogTemplate = m_hDialogTemplate;<br />
HINSTANCE hInst = AfxGetResourceHandle();<br />
if (m_lpszTemplateName != NULL)<br />
{<br />
hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);<br />
HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);<br />
hDialogTemplate = LoadResource(hInst, hResource);<br />
}<br />
if (hDialogTemplate != NULL)<br />
lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);<br />
<br />
if (lpDialogTemplate == NULL)<br />
return -1;<br />
|
|
|
|