|
I'm not sure if this technique is possible in Windows, but it is under Unix with ELF loaders.
Write a shared library (.so - equivalent to .dll in Windows), in which you define extern "C" void* malloc(size_t s) . Then have the shared library to be preloaded before all other DLLs are loaded. Then the linker will not link the system malloc since it has already been loaded.
To chain your malloc with the system's malloc, you simply load the system shared library dynamically in your shared library, and retrieve the pointer to the system's malloc.
So, in your DLL you will have code kind of like this:
void* (*real_malloc)(size_t);
DllMain() {
HANDLE h = LoadLibrary("whichever_dll_that_contains_malloc.dll");
real_malloc = (void*(*)(size_t))GetProcAddress("malloc");
}
extern "C" __declspec(dllexport) void* malloc(size_t s) {
do_some_stuff();
void* ptr = real_malloc(s);
return do_something_more_perhaps(s);
} Then have the linker preload this DLL. I'm not sure it's possible in Windows, but I have a hunch it is. I know it's possible to hijack DLLs, and that's basically what this is. Needless to say, you'll need to link against the runtime dynamically.
--
Suche Wissen über Alles.
Der Student
|
|
|
|
|
I have sorting issue with MMC on Win2000 platform ( works fine on XP,2003)
Open Computer Management in MMC (compmgmt.msc), Select System Tools try to sort by Name on list control. Sorting fails ( Nothing happens ) Do the same on XP , 2003 works fine.
Anybody knows the reason ? And how solve it ?
Thanks
Sandeep Naik
|
|
|
|
|
I can reproduce this on my Windows 2000 machine, but since there are only six items in that list, I'm not going to worry much about it. Is it causing you grief in some programming context?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Oh yes I don't have problem with compmgmt.msc but we have our own .msc file and we lot of items in that list. And with SORT its big problem.
Sandeep Naik
|
|
|
|
|
I have an application I am writting that needs to run for any user logged on. The problem lies in the fact that if User1 switches out (not logs out), and then user2 logs in, another instance of my application runs, which is ok, except the compete with each other.
What I want to happen is to be able to tell if the user the program is running under is no longer the active user, then my program can sleep until it becomes the active user again.
IE: User1 longs in, starts instance 1, and switches out. User2 logs in, starts instance 2. Instance 1 knows its no longer active and goes to sleep. User2 eventually switches out, and user1 comes back. Instance2 goes to sleep, and instance 1 wakes up.
Any ideas?
|
|
|
|
|
Are you running your application on Windows Terminal Services also ?
i.e. Two users can concurrently login
Sandeep Naik
|
|
|
|
|
I suppose so. Its standard windows XP, both pro and home can do this. I understand all NT kernal OSs can do it as well although its not as easy to do as it is under windows XP.
|
|
|
|
|
Process this winbdow message your application:
WM_WTSSESSION_CHANGE
The WM_WTSSESSION_CHANGE message notifies applications of changes in session state.
The window receives this message through its WindowProc function.
See also:
WTSRegisterSessionNotification
The WTSRegisterSessionNotification function registers the specified window to receive session change notifications.
|
|
|
|
|
You can use the standard single instance checking mechanisms (like a mutex) but prefix the mutex name with "Global\" to make it visible in all terminal services sessions. That way your code can tell if another instance of the app is running in any session.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
"die"
ahhhh!
"diet"
AAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!
|
|
|
|
|
Well there are multiple ways to acheive this functionality:
1) Use registry entries under HKLM, which is common for all users logged on to convey any message between different users.
2) I assume that both your program are using/modifying some common files, that is the reason, you are having problems, in that case, you can think of using semaphores to lock the files. Don't know if this would solve the problem
Well to add to your problem, a doubt i have, is if you are using Windows XP, it supports only one session, so if user1 have switched out and user2 wants to logon, when user2 logs on, XP switches out user1.
Are you sure this is not applicable to you?
- Shailesh
|
|
|
|
|
Well to answer these 3 replies..
1. I am not using a 'windowed' application, so I do not have any windows message loop, and therefor I can not look for a switch session message, although now that I know its called a 'session' I may be able to find more help. However I am unsure exactly what you mean by sessions here, so it may be a red herring for me.
2. Just finding out if another instance of my program is running does not help me. I need to find *which* is the one that belongs to the currently active user.
3. My program is talking to a server and it monitors the local users machine. The problem is two fold. For one machine the server will get two reports (or more, one for each user logged in) from the same box. The second problem is the server tells my program to give the user some information, such as they do not have any anti-virus software running. The problem is, if user1 and user2 are logged in, with user2 as the active user, the user1 instance may pick up the message and user2 will never see it.
So what I need is to figure out if *this* instance is the active user instance. If the answer is no, I go to sleep until it is. Otherwise I operate normally.
So it doesn't really come down to having only one instance of my program running or any interprocess communicatiion. I just need to tell if *this* user is the active one, and so far, I can not find a way to do that.
|
|
|
|
|
I was looking at task manager and a bunch of things are running as 'SYSTEM'. If I switch users, they are still running with no duplicates.
I am thinking I can run my app as user system it will solve my problem. However, I do not know how to do this. Also, are there any restrictions a process running under user system have? Can something running under user system still pop message boxes and web pages that will be visible to all users?
Thanks,
--DeepT
|
|
|
|
|
If I wanted to enter a string of characters from the command line and then pass them to a class method and then a private variable how would I do this? I'm thinking along the lines of this but I'm getting a number of errors using the following code. Can Anyone tell me what I'm doing wrong? Thanks in advance for any help you can give me.
Cheers,
lordmickel
////////////////////// .cpp file //////////////////////////////
#include <iostream>
#include <cstdlib>
#include <string>
#include "details.h"
using namespace std;
int main(){
cout << Enter driver name: " endl;
string driver_name;
cin >> driver_name;
details driver;
driver.set_name(driver_name);
return 0;
}
/////////////////// end of .cpp file ////////////////////////////////////
/////////////////////// the class /////////////////////////////////////////
#ifndef DETAILS_H
#define DETAILS_H
class details
{
public:
int get_name();
int get_grade();
void set_name(string name);
void set_grade(int the_grade);
private:
string name;
int grade;
};
string details::get_name()
{
return name;
}
int details::get_grade()
{
return grade;
}
string details::set_name(string the_name)
{
name = the_name;
}
void details::set_grade(int the_grade)
{
grade = the_grade;
}
#endif
/////////////////////////////////////////////////////////////////////
Errors:
--------------------Configuration: text_class - Win32 Debug--------------------
Compiling...
text.cpp
c:\program files\microsoft visual studio\myprojects\text_class\details.h(7) : error C2146: syntax error : missing ';' before identifier 'get_name'
c:\program files\microsoft visual studio\myprojects\text_class\details.h(7) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\text_class\details.h(9) : error C2061: syntax error : identifier 'string'
c:\program files\microsoft visual studio\myprojects\text_class\details.h(13) : error C2146: syntax error : missing ';' before identifier 'name'
c:\program files\microsoft visual studio\myprojects\text_class\details.h(13) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\text_class\details.h(13) : error C2501: 'name' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\text_class\details.h(20) : error C2143: syntax error : missing ';' before 'tag::id'
c:\program files\microsoft visual studio\myprojects\text_class\details.h(20) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\text_class\details.h(20) : fatal error C1004: unexpected end of file found
|
|
|
|
|
|
I assume u mean, #include <string> should be #include <cstring> ?
I tried that and it didn't work I got the same errors. The book I'm using says to use #include <string>.
Cheers.
|
|
|
|
|
I assume u mean, #include <string> should be #include <CString>?
I tried that and it didn't work I got the same errors. The book I'm using says to use #include <string>.
Cheers
|
|
|
|
|
There is a big difference between a string object and CString object. The former is STL while the latter is MFC. Also, there is no such file as cstring . Had you used it, the preprocessor would have rightfully complained.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Compare the positions of your using namespace std and #include "details.h" lines. Since the include is first, the compiler hasn't seen the using yet, so it doesn't know what string is. Either change the code to "std::string" (preferred) or put the using in details.h (bad practice once you get to large programs as many usings can lead to name collisions, which is what namespaces were designed to prevent).
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
You cannot stop me with paramecium alone!
|
|
|
|
|
Thank you very much Mike, that makes perfect sense. I'll look at it tomorrow.
Cheers,
Graeme
|
|
|
|
|
lordmickel wrote:
cout << Enter driver name: " endl;
There are two problems with this statement. I'm sure your compiler has already pointed them out.
lordmickel wrote:
c:\program files\microsoft visual studio\myprojects\text_class\details.h(7) : error C2146: syntax error : missing ';' before identifier 'get_name'
How are we supposed to know what line 7 of details.h is? Mark the lines that are in error. It would also be beneficial to fix the #include statements (so that we don't erroneously suggest a file that is already being included).
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Sorry for the most unhelpful error message. I know how annoying that is. I managed to sort the problem out thanks to everyone's help.
much appreciated.
lordmickel
|
|
|
|
|
For an i/o bound processing job, which would be faster:
1) Memory map the file and process it in place
2) Use overlapped I/O, reading into one of 2 buffers, while processing the other (pipelined)
On a single cpu, would I get any benefit from #2?
On a dual cpu, does #1 get no improvement over that on a single cpu?
Thanks.
|
|
|
|
|
If you are truly I/O-bound then I suspect that overlapped I/O would be fastest since it would allow for I/O to happen simultaneously with data processing. You might need to adjust your buffering scheme to take maximum advantage. One option is a buffer/thread pool where some (or one) buffers can be read, some processed, and some written, all at once.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Scott H. Settlemier wrote:
For an i/o bound processing job, which would be faster:
1) Memory map the file and process it in place
2) Use overlapped I/O, reading into one of 2 buffers, while processing the other (pipelined)
For me it would really depend on the nature of the processing and the app.
Scott H. Settlemier wrote:
On a single cpu, would I get any benefit from #2?
Other than having code that would scale to hyperthreaded and multi processor hardware well ... probably not.
[edit] DOH! i read it as IOCP, see peters reply for more appropriate reply [/edit]
Scott H. Settlemier wrote:
On a dual cpu, does #1 get no improvement over that on a single cpu?
The file is on one disk and is being read by one thread, i would say no (not directly, but you would indirectly).
Each method has its strengths, it really depends on the requirements.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
1) A Memory Mapped File can avoid the cost of copying data around (file cache <==> your buffers), this is especially helpful with large amounts of data
2) Overlapped I/O - if supported by the hardware, but any decent box should now - works directly between disk controller and RAM, without requiring the CPU.
Which one is better strongly depends on your application, and the box it runs on. Share some more info (what kind of I/O, how often, how much data, etc.)
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist Fold With Us! || Agile Programming | doxygen
|
|
|
|