|
I think that Visual C++ does some trivial optimisation even in debug builds.
When line 0 is deleted, it is trivial for the compiler to know that line 1 does nothing and the the whole loop is useless.
For the other case (line 1 deleted), I don't see how it can be "optimized" except if intrinsic inline functions are enabled.
The best thing to do is to take a look at the assembler code while debugging. You will see what the compiler has generate.
At first, I would think that the compiler has detected that the loop is useless when timing is really near 0ms.
Probaly when you have both lines, the complexity is higher than what VC will try to optimize...
Philippe Mori
|
|
|
|
|
Hi.
I am becoming more familiar with Win32 API especially for winsock and core Windows including threads, processes, and DLL. I began learning programming about a year ago and my first and currently more proficient language is C++. I have no prior programming experience and not knowledge of C. Nonetheless, Win32 API and other Windows programming tools as well and good DOS and linux programs all make use of C run-time library.
I would like to know ways to allocate and deallocate a chunk of memory space. In C++, I am familiar with the new and delete operators. However, you have to define the data type you before allocating memory. I C, I believe you can allocate a chunk of memory (BYTE data type?) and store anything there. Furthermore, you can use function, I believe free(), to free the memory.
What are some ways to allocate/deallocate memory using C/C++ other than new/delete?
Thanks,
Kuphryn
|
|
|
|
|
void * ptr = malloc(NumberofBytes);
There is also calloc, and GlobalAlloc
Look 'em up to see the usage.
|
|
|
|
|
C : malloc, realloc, calloc, free
C++ : new, delete, GlobalAlloc, GlobalFree, LocalAlloc, LocalFree...
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Okay. Thanks.
Wow. I have not seen GlobalAlloc, GlobalFree, LocalAlloc, or LocalFree in my limited experience using C++. I think the only book that goes over them is by Bjarne Stroustrup.
Kuphryn
|
|
|
|
|
GlobalAlloc, LocalAlloc etc are actually part of the Win32 API, NOT the C++ language - they can be used from any language that can call a function just about (Visual Basic anyone )
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Stuart Dootson wrote:
ForumVisual C++
Subject:Re: Memory Allocation :: C/C++
Sender:Stuart Dootson
Date:2:44 15 Aug '02
GlobalAlloc, LocalAlloc etc are actually part of the Win32 API, NOT the C++ language - they can be used from any language that can call a function just about (Visual Basic anyone )
every 5th vb instruction is appended with one of these
Rutger Ellen
|
|
|
|
|
|
Is there a way to send send messages to controls in an HTML view?
I want to display a page and programmatically emulate button clicks
on controls and links etc.
Happy programming!!
|
|
|
|
|
Does anybody know of an easy way to change the font color of Static Text within mfc dialogs? It seems such a trivial thing to do, yet I have not yet found a way of doing it...
Thanks for your help.
Steve.
|
|
|
|
|
|
My code is completely unicode enabled using the _TCHAR style macro's. However, when I type Japaniese (or any other double byte characters for that matter) my dialogs still show the corrupted single byte text.
Can someone direct me to documentation or give me a tip on how to get edit controls, lists boxs, etc. to show the proper dbcs character sets?
The build I tested on was using both #define UNICODE and #define _UNICODE
This is my first attempt at making an app that supports dbcs characters, so I appologize if this is a basic question.
Thanks!
. djrisc .
|
|
|
|
|
I forgot to include that I also tried to use #define _MBCS
This generated some compiler issues due to type definition changes. However, this kind of boggles me since both ASCII and UNICODE works smoothly.
. djrisc .
|
|
|
|
|
You need to change the font in the dialog resource to "MS Shell Dlg". VC 6 sets it to "MS Sans Serif" which doesn't have DBCS support. Sadly, you'll have to change the font name every time you change the resources, because VC 6 doesn't understand Shell Dlg and will reset it back to Sans Serif.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Mike,
Perfect! Thanks a million! Worked like a charm.
. djrisc .
|
|
|
|
|
Does someone have some sample C++ programs (Visual C.NET) that do some real simple dialogue interface to a DOS program ?
I have a command line DOS C++ program that opens an input file (fopen()) reads it, manipulates it and writes it out using the same file name but in a different directory. Also, there can be some input required by the user during the processing.
I need a dialogue window that browses for a file name, followed by a dialogue that browses for a directory path (output directory) and can pass these values to my program. Also the ability to trigger a dialogue during my processing.
I am overwhelmed by all the examples provided by microsoft, when all I need is this !
Do any of you seasoned Windows C++ programmers have a shell that I can work with ?
Any comments or advice welcome
Thanks
|
|
|
|
|
I am buildng a COM dll that uses C++ dll. When registering the component C++ gives me an error - unable to locate a C++ dll (although compiling and linking were fine). How can I modify Project setting or environmental variables to tell RegSvr32 where to look for the dll?
Thanks,
This is the error I am getting:
Performing registration
RegSvr32: LoadLibrary(".\Debug\MyCOM1.dll") failed.
GetLastError returns 0x0000007e.
OleMainTreadWndName: RegSVR32.exe - Unable to locate DLL
|
|
|
|
|
That's a known error. Don't forget that depending on what libraries you link with, the DLL when loaded for registration may be automatically trying to load sister dlls, and in this case may not find one of them.
For instance, if you link with winwin.lib with at least one method implementation taken from it (_dllimport), and winwin.dll does not exist, then registration fails.
The error message tells you that's about the main dll, while it's not !
|
|
|
|
|
Hi All,
Anybody know of a way to get the interface of an existing in-proc ATL COM object that has been cocreated in a separate process? I know the name of the .exe that has an instance of the object, and I would like to grab the interface pointer to the existing object to register for events.
Thanks in advance,
Aaron
|
|
|
|
|
Option 1 : writing code properly
Looks like you should use COM aggregation. In other words, the .exe must republish the interface published by the ATL COM object.
ATL provides good classes for this purpose (CInnerUnknown, InternalQueryInterface(), ...).
Of course it assumes that you are able to recompile the .exe
|
|
|
|
|
Option 2 : use dirty windowing
Nothing prevents you to add windows messaging between your client .exe and the other .exe.
For this purpose, all you have to do is, inside the ATL code, create and attach a unique window when the ATL COM object is created and attached to the .exe
And then, from your client .exe, just find this window (::FindWindow(...)) and start doing ::SendMessage() to it.
That's dirty coding, but that's how a lot of software work on Windows.
PS : windows messaging is fine for event subscription.
|
|
|
|
|
Well, basically, the object that I need information from has a bunch of containers. These are just STL containers wrapper in COM interfaces, but they are sort of invisible now. I need to be able to display the state of these containers. This is just for debugging.
Maybe some scenario like this, sort of:
The .exe creates an instance of my object. In the final construct, I would like to be able to fire up a window with a grid in it, that is updated by my in-proc ATL object, to display the internal state of this object as it is operated on by its host .exe. The events indicated contained data has changed. So the view of the object needs an interface to query the contents of the internal containers to the object each tim they are changed. That make sense? Since this is only for debugging the object itself, I don;t want to change any code in the host .exe itself.
Maybe I should just create another COMO object, this one an .exe server, and keep the interface to that one in my in proc object? Also, I need to make use of some MFC dependent stuff in the "view" object, and have been having some trouble donig this in ATL code. They don't seem to mix. Basically, I just need a big window/dialog box that I can communicate with via an interface
Thanks,
Aaron
|
|
|
|
|
"Maybe I should just create another COMO object, this one an .exe server"
Actually, what you want to do is to convert your in-proc object to a local server. Then you can have multiple processes accessing the same process space. Each will have a seperate instance of the object. So info that is to be shared, must be global between the instances.
This is the architecturally sound way of doing what you want. ATL vs MFC makes no difference in the basic architecture. You can do this with either framework.
|
|
|
|
|
How do I create an .exe server in MFC? Something with a GUI?
|
|
|
|
|
Using the app wizard:
Create a new MFC exe project.
On the 3rd page select the Automation checkbox.
Complete the wizard.
Use the class wizard, automation tab to add a new COM interface to the project. You can base the new class on COleServerDoc or COleServerItem. From there it gets a little complicated.
1. My recommendation is to build the .exe as an ATL app.
2. d MFC support to the project.
3. Add a COM interface using the Insert New object menu item.
4. Port your existing code into the new object.
If you are clever enough, you can skip step 3 and simply add your existing COM object classes to the ATL project.
|
|
|
|