|
Access to the HKEY_LOCAL_MACHINE subtree is protected.
MsmVc wrote: Same code when i am running on Vista then give error.But when i run code Run AS Admin then show UAC Enable or Disable.
It looks like the only way to obtain it (It looks like you cannot programmatically elevate current process privileges, see, for instance here[^]) however, I'm not an expert.
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]
|
|
|
|
|
who can desribe the difference between new and malloc function and
I want to know how they work.Thanks!
|
|
|
|
|
Googling[^] gives many usefull hits, like this[^] for example. Do these answer your question or did you mean a more indept view on these?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
Short answer: new gives a chance for objects initialization (by calling constructors) and cleanup (delete calls destructors) while malloc provides bare allocation functionality.
Short advice: while doing C++ development always use the new/delete approach.
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]
|
|
|
|
|
new creates new objects, malloc just reserves you a lump of memory and gives you a pointer to it. So when you say:
foo *p = new foo;
you're asking the compiler to generate the code for creating an original instance of foo (whatever that is) and to tell you where it is in the program's address space. Generally this means:
- The compiler generates code for reserving a lump of memory to store the object in
- It calls the appropriate constructor for foo and runs it on that lump of memory.
On the other hand when you say (in C):
foo *p = malloc( sizeof( foo ) );
you're saying "give me a lump of bytes that happens to be the size of a foo and I'll treat it as a foo." There can be any old rubbish in there. If you want it initialised into any reasonable state you've got to do it manually. Incidentally this is one of the reasons you'll find C programmers immediately memset ting allocated memory blocks or using calloc instead - it gets the memory into a known state. You'll also find that many decent C programmers bundle allocation and initialisation into functions and call them things like "construct_foo" to keep the operation atomic.
Incidentally there are loads of places you can plug into the object creation sequence process in C++ but very few (i.e. none I know of) of modifying the way malloc works in C. In C++ you can modify how the memory is reserved (by overloading operator new or using placement new), what to do if the allocation fails (set_new_handler ) and how the object is initialised (by writing constructors).
One final point. If new fails it throws an exception and winds back any initialisation or memory reservation that's already been completed. The exception is either bad_alloc if the memory reservation fails, or something from the constructor. If malloc fails it returns a NULL pointer, which is another good reason to use initialisation functions in C - you can handle all the errors in one place.
Cheers,
Ash
|
|
|
|
|
The best thing to do is to put a breakpoint on the line where new is called and then step into the code.
You can see all the things that it does and finally calls into the Windows API.
You could also overload new in one of your classes and then debug into it.
|
|
|
|
|
|
Hi,
I have to add property pages to a property sheet at runtime.
How can I exchange data of this page at runtime?
|
|
|
|
|
DoDataExchange() is not supposed to be called directly. You can use UpdateData().
|
|
|
|
|
You cannot do this.
You will have to do this using the functions instead.
Internally, the DDX_xxx wrappers do exactly this.
So for controls created dynamically you will have to do this yourself.
|
|
|
|
|
Hey,
this is my code:
connect(s, (SOCKADDR*) &addrin, sizeof(addrin));
send(s, stRequest.c_str(), stRequest.length(), 0);
cout << "stRequest sent." << endl;
recv(s, buffer, sizeof(buffer), 0);
cout << "buffer received." << endl;
Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever..
Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar..
I couldn't really find something helpfull on google, so yea I thought maybe you guys could help me out.
|
|
|
|
|
|
ALLERSLIT wrote: Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever..
Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar..
There are multiple choices:
- adjust the send/receive timeouts with setsockopt(), see SO_SNDTIMEO and SO_RCVTIMEO
- use non-blocking/asynchronous sockets, makes event based applications so much easier
- use a C++ networking library/API offering timeouts or search for a HTTP client class, would be my recommendation
Happy coding!
|
|
|
|
|
hello guys...im doing small project in TAPI.
- I show all the available lines in combo box.
- Now when I select a line device from combo box; I get its index and pass it to lineOpen(), but this does't work.
- Finally I hard-coded the line device id (ZERO in this case) which worked absolutely fine.
My question is: why does the combo box method is't working as it should be. What should I do?Any idea? thnx
|
|
|
|
|
overloaded Name wrote: My question is: why does the combo box method is't working as it should be. What should I do?Any idea? thnx
What do you mean with that?
Could you please post the relevant code?
Have you checked the method's return value?
(To sum up: "have you used the debugger?")
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: Could you please post the relevant code?
well there is nothing much for the code. I get index and pass it which does't work.
If I hard cord the line device id then it works fine. Here is the code
DWORD index = m_comboDevices.GetCurSel();
OpenLine(index);
WaitForIncomingCall(index);
CaptureEvents();
Everything is fine so the only problem is; selecting the line device from combo box is not working.
|
|
|
|
|
There are two possible problems in the obove code:
1. You do not check that the return value from GetCurSel() is a valid response (i.e. no error checking).
2. Are you sure that the CombBox index value is the same as the line number? What does WaitForIncomingCall() actually do?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
overloaded Name wrote: DWORD index = m_comboDevices.GetCurSel(); //m_comboDevices = control variable of combo box
OpenLine(index); //a function opens a line with provided argument
WaitForIncomingCall(index); //it waits for incoming calls on the provided line (argument)
CaptureEvents(); //this function captures events.
The correct approach here is:
DWORD index = m_comboDevices.GetCurSel();
if (index == CB_ERR)
{
}
..
Moreover: why don't you use the debugger (or, for instance, the TRACE macro) to inspect index value?
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]
|
|
|
|
|
Hello,
I am hoping that someone might know how to execute a user-mode executable from a driver? Either DDK or for mac.
I have found that neither exec(), fork() or system() work in the DDK. What other compilers could these statements work for (windows/mac)?
|
|
|
|
|
I don't think that can be done (nor should be done) directly, as the protection would be insufficient. Maybe the driver could get it scheduled through Windows Scheduler though, I don't really know.
|
|
|
|
|
There is no direct way to do this directly from a driver.
Usually there is a support application or service that runs in user mode and waits on a named event.
The driver then signals this event whenever a process needs to be created.
In the user mode app, the wait is satisfied and it creates the process.
|
|
|
|
|
Why?
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]
|
|
|
|
|
The purpose would to be to run a portal program for all the applications on a storage device.
|
|
|
|
|
What is the best way to connect an database through an worker thread ?
I teach from here[^] how to use an worker thread ...
Ok , but in worker thread I use theApp global member variable which have an database connection ... but the problem is that not every time thread unconnect database or destroy theApp.m_pDB member variable from CMyApp::ExitInstance() event .... I don't know why ?!
So , can you tell me how to connect to an database from an worker thread ? Thank you !
|
|
|
|
|
mesajflaviu wrote: So , can you tell me how to connect to an database from an worker thread ?
I would be inclined to connect to the database in the primary thread, and then pass the CDatabase pointer to the secondary thread.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|