Click here to Skip to main content
15,923,689 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to generate uid for header files PinPopular
CPallini3-Nov-10 2:50
mveCPallini3-Nov-10 2:50 
AnswerRe: how to generate uid for header files Pin
«_Superman_»3-Nov-10 6:17
professional«_Superman_»3-Nov-10 6:17 
GeneralRe: how to generate uid for header files Pin
lakshman rao8-Nov-10 2:56
lakshman rao8-Nov-10 2:56 
AnswerRe: how to generate uid for header files Pin
yu-jian4-Nov-10 15:20
yu-jian4-Nov-10 15:20 
QuestionNumber of instances running Pin
ganesh.dp2-Nov-10 23:53
ganesh.dp2-Nov-10 23:53 
AnswerRe: Number of instances running Pin
GAJERA3-Nov-10 0:42
GAJERA3-Nov-10 0:42 
AnswerRe: Number of instances running Pin
ShilpiP3-Nov-10 1:58
ShilpiP3-Nov-10 1:58 
AnswerRe: Number of instances running Pin
Sauro Viti3-Nov-10 3:55
professionalSauro Viti3-Nov-10 3:55 
As long as your code compiles to an exe, you can do it this way:


  1. Add the following lines on top of one of your cpp files:
    C++
    #pragma data_seg("shared")
    LONG g_counter = 0; // This variable is allocated on a page shared between processes...
    #pragma data_seg()
    
    #pragma comment(linker, "/section:shared,rws")
  2. Execute the following instruction as soon as possible at startup of your application:
    C++
    InterlockedIncrement(&g_counter);
  3. Execute the following instruction immediately before exiting from your application:
    C++
    InterlockedDecrement(&g_counter);
  4. When you need the number of instance of your application currently running, use this code:
    C++
    LONG instances = InterlockedExchangeAdd(&g_counter, 0);


This method works properly only with exe because they are never relocated while loaded; the trick is to create a section whith the read, write and shared attributes and put there a variable used to count the instances. This way that variable is shared between all the instances of your application, and you can use the Interlocked Variable Access[^] functions to safely access the variable.
See also data_seg (C/C++)[^] and /SECTION[^] for more details on how this code works.
QuestionUSB mass storage vs USB HID Pin
Subrat Patnaik2-Nov-10 23:31
Subrat Patnaik2-Nov-10 23:31 
AnswerRe: USB mass storage vs USB HID Pin
«_Superman_»3-Nov-10 6:24
professional«_Superman_»3-Nov-10 6:24 
GeneralRe: USB mass storage vs USB HID Pin
Subrat Patnaik3-Nov-10 19:06
Subrat Patnaik3-Nov-10 19:06 
GeneralRe: USB mass storage vs USB HID Pin
«_Superman_»4-Nov-10 7:02
professional«_Superman_»4-Nov-10 7:02 
QuestionSleep Function Pin
MsmVc2-Nov-10 22:43
MsmVc2-Nov-10 22:43 
AnswerRe: Sleep Function Pin
CPallini2-Nov-10 22:59
mveCPallini2-Nov-10 22:59 
GeneralRe: Sleep Function Pin
GAJERA2-Nov-10 23:10
GAJERA2-Nov-10 23:10 
GeneralRe: Sleep Function Pin
CPallini3-Nov-10 0:07
mveCPallini3-Nov-10 0:07 
GeneralRe: Sleep Function Pin
GAJERA3-Nov-10 0:26
GAJERA3-Nov-10 0:26 
GeneralRe: Sleep Function Pin
CPallini3-Nov-10 2:43
mveCPallini3-Nov-10 2:43 
GeneralRe: Sleep Function Pin
GAJERA3-Nov-10 17:45
GAJERA3-Nov-10 17:45 
AnswerRe: Sleep Function Pin
Cedric Moonen2-Nov-10 23:09
Cedric Moonen2-Nov-10 23:09 
AnswerRe: Sleep Function Pin
Chris Meech3-Nov-10 2:31
Chris Meech3-Nov-10 2:31 
AnswerRe: Sleep Function Pin
Stephen Hewitt3-Nov-10 4:16
Stephen Hewitt3-Nov-10 4:16 
AnswerRe: Sleep Function Pin
«_Superman_»3-Nov-10 6:29
professional«_Superman_»3-Nov-10 6:29 
Questionproblems with arrays Pin
rezen852-Nov-10 22:28
rezen852-Nov-10 22:28 
AnswerRe: problems with arrays Pin
Richard MacCutchan2-Nov-10 22:32
mveRichard MacCutchan2-Nov-10 22:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.