|
Click here ->[^]
May be this link will help you..
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
As long as your code compiles to an exe, you can do it this way:
- Add the following lines on top of one of your cpp files:
#pragma data_seg("shared")
LONG g_counter = 0; #pragma data_seg()
#pragma comment(linker, "/section:shared,rws") - Execute the following instruction as soon as possible at startup of your application:
InterlockedIncrement(&g_counter); - Execute the following instruction immediately before exiting from your application:
InterlockedDecrement(&g_counter); - When you need the number of instance of your application currently running, use this code:
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.
|
|
|
|
|
hi all,
i have an application which requires to monitor USB activities(only USB mass storage devices).
i need a small help on how to differentiate between USB mass storage devices and USB Mouse/Keyboard/Printer (USB HUMAN INTERFACE DEVICES) etc...
could it be done through device ID??
some code will help a great deal...
Thank You all.
|
|
|
|
|
In USB terminology, an interface is what we normally would call a device.
For example, a printer can have a scanner and mass storage in a single unit.
Each interface has a property called an interface class.
For mass storage, this property will have a value of 8.
You can see a list here - http://www.usb.org/developers/defined_class[^]
You can get this by reading the configuration descriptor of the device.
|
|
|
|
|
Hi _Superman_,
i already know the device descriptor properties...
however, if i could get some code help it would be great....code on how to enumerate the base class of a USB device....
|
|
|
|
|
The interface class is one of the fields in the interface descriptor.
The field name is bInterfaceClass .
So after you get the interface descriptor, check if bInterfaceClass is 8 for Mass Storage.
|
|
|
|
|
Hi all
I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min.
Is it possible.Please advice me.
|
|
|
|
|
Yes, it is possible: just set the Sleep interval to 1 minute (or whatever appropriate) and iterate it 30 times, then, whenever you need to shorten the wait delay, decrease the iteration limit.
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]
|
|
|
|
|
But if you give sleep 1 hour, then what happen?
I think it is not possible or we need to interrupt hardware.
|
|
|
|
|
Well, you may use WaitForSingleObject instead.
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]
|
|
|
|
|
OK,but How we stop sleep function? as we already put sleep for 1 hour.
|
|
|
|
|
You cannot stop it (well, without a hammer...).
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]
|
|
|
|
|
|
On the other hand, if you have to use a sleep of 30 minutes, it is likely that your design could be improved. For what reason do you need to sleep so long ?
|
|
|
|
|
What you are looking for is a WakeUp function. Unfortunately it doesn't exist. Since your thread is effectively blocked on Sleep, you need to handle this differently. This article [^] may give you some idea of how to accomplish what you are looking for.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
You say you want to sleep for 30 minutes but might at a later stage decide to alter the duration. This begs the following question: Who is doing the deciding? If you've called Sleep[^] with the full duration it obviously can't be the calling thread because it's sleeping. Some possible solutions are:
- Sleep for a shorter duration and periodically check on the same thread (do this in a loop).
- Use the WaitForSingleObject[^] function with the
dwMilliseconds parameter set to 30 minutes and for the hHandle parameter use a synchronisation object signalled by another thread (to abort the sleep).
Steve
|
|
|
|
|
Depending on your requirement, you could probably use SleepEx .
|
|
|
|
|
hi,i have written the code as shown below and it's to capture real time temperature but i have a problem to capture the temperature readings which i declare it as
tmpVALUE .I tried to place the readings to the arrays but it gave me an error:(error:
tmpVALUE was not declared in this scope.Please advice.
float tmpVALUE = 0;
int i=0;
void setup()
{
SensorEvent.setBoardMode(SENS_ON);
XBee.setMode(XBEE_ON);
delay(50);
USB.println("Start");
delay(100);
}
void loop()
{
char MSG[10]={tmpVALUE};
char* MSG0=0;
int i=0;
float tmpVALUE=0;
tmpVALUE = SensorEvent.readValue(SENS_SOCKET5);
if(tmpVALUE>0.5)
{
tmpVALUE=((tmpVALUE-0.500)/0.010);
}
else
{
tmpVALUE=tmpVALUE/0.010;
}
delay(100);
XBee.print("Temperature: ");
XBee.println(tmpVALUE);
for (int i=0; i<10; i++)
{
MSG0[i]=tmpValue;
MSG1[i]=tmpValue;
MSG2[i]=tmpValue;
MSG3[i]=tmpValue;
MSG4[i]=tmpValue;
MSG5[i]=tmpValue;
MSG6[i]=tmpValue;
MSG7[i]=tmpValue;
MSG8[i]=tmpValue;
MSG9[i]=tmpValue;
}
xbee.OFF();
delay(5000);
}
|
|
|
|
|
I cannot see how this would even compile. You have declared <pre>tmpVALUE</pre> at the top of your module and also in the function <pre>loop()</pre>. Your initialisation of <pre>char MSG[10]={tmpVALUE};</pre> is allocating a <pre>float</pre> to a <pre>char</pre>, and the variables <pre>MSG1</pre> ... <pre>MSG9</pre> have not been defined.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Sorry for the trouble,but what i did was actually referred from c++ book.I do not know c++ that well.Do you have any better way of writing the arrays?As the declaration (tmpVALUE) is to capture the real time temperature.
|
|
|
|
|
I don't know what C++ book you are using but it is obviously not a very good one if that is an example of the sort of code it is giving you. I suggest you get hold of a better one and start with some simple programs before trying the more advanced stuff.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
As i understand is that you use the value of tmpVALUE before declaring it.
char MSG[10]={tmpVALUE};
char* MSG0=0;
int i=0;
float tmpVALUE=0;
The code should be like that
float tmpVALUE=0;
char MSG[10]={tmpVALUE};
char* MSG0=0;
int i=0;
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
hi,
thanks for the prompt reply.I have change the codes but it gave me an error: re-declaration of
float tmpVALUE=0; .From what i understand from the c++ reference book,somehow or rather
float tmpVALUE=0; at the top my coding is already acting as a global.
|
|
|
|
|
Hi,
I am currently debugging an MDI application created with VC++ 6 which crashes randomly in debug configuration.
Sometimes, I get an assertion when a new document is created which comes from "Objcore.cpp / AfxAssertValidObject() / AfxIsValidAddress()" and says that the "pDocument" pointer is invalid.
I have created a second MDI test application that reproduces the architecture of the first application.
This application only allows one document at a time (a kind of SDI ).
Each time a document is closed, a new one is created automatically via a custom WM_COMMAND message and the new document is closed via ID_FILE_CLOSE.
All messages are sent using PostMessage.
The result is that the closing of the current document and the opening of the new document are not synchronized.
Here is the code added in the MDI test application:
#define ID_FILE_INFINITE 50000
BEGIN_MESSAGE_MAP(CTestMDIApp, CWinApp)
ON_COMMAND(ID_FILE_INFINITE, OnCommandOpenDoc)
END_MESSAGE_MAP()
void CTestMDIApp::InitInstance()
{
m_pDocTemplateInfinite = = new CMultiDocTemplate(...);
}
void CTestMDIApp::OnCommandOpenDoc()
{
CTestMDIDoc* pDoc = static_cast< CTestMDIDoc* >(m_pDocTemplateInfinite->OpenDocumentFile(0));
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_CLOSE);
}
CTestMDIDoc::~CTestMDIDoc()
{
TRACE(_T("PostMessage(WM_COMMAND, ID_FILE_INFINITE)\n"));
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_INFINITE);
}
When ID_FILE_CLOSE command param is processed, the following code is run:
CFrameWnd::OnClose()
CDocument::OnCloseDocument()
delete this;
~CTestMDIDoc()
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_INFINITE);
CDocument::~CDocument()
m_pDocTemplate->RemoveDocument(this);
I know that PostMessage is asynchronous so my opinion is that in my test application,
a new document may be created before the previous one has finished its removing from m_pDocTemplate.
Is it the reason why a new document pointer becomes randomly invalid?
Thanks in advance for your answers.
Thanks and regards
Pascal
|
|
|
|
|
You seem to have reached the answer yourself. You open a new document and then post a message to close the current one, which also deletes the document object. This seems the wrong way round to me; you should close the current document first and then open the new one, preferably by direct calls to your close and open routines or via SendMessage() .
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|