|
Yea, we tried that, I have no idea how Overlapped works even with the MSDN libraries. (we used them to get as far as we did)
it seems as though if WaitCommEvent() is spawned (with it's parameters existing within a class)
and then
ComSetEvent() is executed from another thread with it's parameters existing fromt he same class, it is suspended until WaitCommEvent is complete. Is this true?
lead2gold
|
|
|
|
|
Aehm, more or less.
Overlapped IO is a feature of the NT Executive (Kernel) and the Win32 API and not related to any classes. The IO Manager (a component of the Executive) executes IO request always asynchronously - if you don't use overlapped IO the calling thread is just blocked until the IO is completed. (In other words: Inside the kernel non-overlapped IO is simulated by using overlapped IO)
However, I am sure you that much interested in the technical details, but want to know how to use it
Overlapped IO is not difficult in general, but a lot of details have to be taken into account. If the information provided by MSDN is not enough, I'd recommend to buy a good book about Windows NT system programming, like Win32 System Programming by Johnson M. Hart. (Note: I haven't read it, but people told me that it's a quite good book).
Hope that helps!
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Every little bit helps and thanks for your advice. I'll definatly look into such a purchase.
lead2gold
|
|
|
|
|
Hi all,
new to C++ programming. i am in HS and taking a C++ course right now. can you guys tell me where to find the "graphics.h" file? I don't have one on my computer. Also what exactly does this do?
Thanks
matt
Matt Millican
http://www.internetmill.com
|
|
|
|
|
Where did you find that you need graphics.h?
Is it a windows API function, a C++ libarary function, or even a reference out of a book?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Paul,
I found some sample code on the internet and it has a line in it that is calling graphics.h.
#include <graphics.h>
Thanks
Matt
Matt Millican
http://www.internetmill.com
|
|
|
|
|
I am attempting to learn to use Microsoft's GDI+, but I cannot figure out where to get the header files. The DLL is all over the place, but none of the other files are presenting themselves...
|
|
|
|
|
You obviously did not search this site, or you'd have read my articles. You need the platform SDK, from the Microsoft site. If you're on a modem, you'll need to order the CD instead.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|
|
Hi,
I did a search for this because I'm sure it must have been asked before but I could find anything so...
I think the subject says it all; I want to change the background colour of my CComboBox to an RGB colour with the least hassle possible. I don't really want to write my own ComboBox class and I don't really want to use one somebody else has written that does a million other things. I'm guessing there isn't anything as simple as .SetBkColor? I can do m_comboBox.GetWindowsDC()->SetBkColour(RGB(X,X,X)) but it doesn't seem to have an effect, even if I call Invalidate...
Any thoughts?
Thanks VERY much,
Philip
|
|
|
|
|
hi,
I got some information from MSDN just have a Look
// This OnCtlColor handler will change the color of a static control
// with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog
// class has an initialized and created CBrush member named m_brush.
// The control will be painted with red text and a background
// color of m_brush.
HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// Call the base class implementation first! Otherwise, it may
// undo what we are trying to accomplish here.
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// Are we painting the IDC_MYSTATIC control? We can use
// CWnd::GetDlgCtrlID() to perform the most efficient test.
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
{
// Set the text color to red.
pDC->SetTextColor(RGB(255, 0, 0));
// Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);
// Return handle to our CBrush object.
hbr = m_brush;
}
return hbr;
}
|
|
|
|
|
I have an VC++ application that uses STL for all core logic and MFC for windowing, and is quite extensive in features. I want to enable other applications to access features of the application.
I was conisdering using COM (automation as a COM server that resides in the exe) for this purpose. Considering the latest developments, particularly .NET, is there any other preferred alternative to this?
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Well, you could make the classes managed for use in .NET but I'm not sure if that is what you want.
"We will thrive in the new environment, leaping across space and time, everywhere and nowhere, like air or radiation, redundant, self-replicating, and always evolving." -unspecified individual
|
|
|
|
|
well, I want it to be accessible from .NET apps as well. My familiarity with .NET is limited - what is the mechanism that I can use, if I want it to be accessible from .NET, VC++, VB etc...
I expect people to be using .NET, VB or VC++. I know COM can be used. I wanted to be sure if there is a better option avaiable.
The application is huge, and porting it to a managed one is ruled out atleast at present.
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
To make the classes managed for use in .NET you just need to instert __gc in the class declaration. For example:
<font color="blue">public __gc class </font>yourClass
{
};
The only downside to this that I just remembered is that you wont be able to use the managed .NET class from a unmanaged program. So I don't think this would be the best option for you.
"We will thrive in the new environment, leaping across space and time, everywhere and nowhere, like air or radiation, redundant, self-replicating, and always evolving." -unspecified individual
|
|
|
|
|
Use COM.
It can run without users need to install the .NET framework.
It can be accessed from VC++ and VB
It can also be accessed from .NET-languages, because they are compatible with COM (interop)
You don't have to make a lot of managed C++ code in your existing native application.
Just my 2 cents...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
|
This is probably a dumb question, but I am a newbie:
I am trying to catch error if an attemp is made to read past the end of an array.
For example I have an array double fVector[10];
Then I have the following code:
try {
for( int n = 0; n < 50; n++ ) {
a[n] = fVector[n];
}
} catch( int ) {
printf("Error!!!");
}
The problem may (and sometimes may not) result if I try to access element #11. But how do I catch that? If I knew the length of fVector, I could add something like this:
if( n > nLength ) throw 1;
but what if I don't know it? How can I trap the error before the application crashes with an invalid memory address error?
Thanks
|
|
|
|
|
There is no guarrantee that an access violation exception will be thrown when you read over the end of an array like that. The address beyond the end of the array may still be valid (i.e. it may contain another variable). Instead, use std::vector, and use the at() method to retrieve values. The at() method checks the array bounds, and throws an out_of_range exception if the bounds are exceeded. Alternatively, std::vector also provides the size() method, so you can do the range checking yourself, and then access the elements like a normal array using operator[].
Dave
|
|
|
|
|
Thanks for your reply.
I know there is no guarantee that the application will throw an exception; however, I would like to catch it (if it's thrown) to avoid the termination of an application.
The reason why I want to stick with an array of doubles (as opposed to using a different class) because the data will be supplied in this format into a DLL by a user.
|
|
|
|
|
If the user is passing an array of double 's into your DLL, you should have them pass the number of values in the array as well. That's the only way to ensure that you don't run off the end of the array.
Software Zen: delete this;
|
|
|
|
|
That's what I am doing right now; however, users can be dumb enough to supply an array of 10 values but set the number of attached values to 20.
I guess I can rephrase the question a little bit:
Is there a way to trap UNEXPECTED error in C++? As far as I can see, you can stick in "throw" where you think the application may fail, but is there a way to assign error handling to the whole routine so that no matter where and why it fails there, go to a specific location. For example in VB, it is achieved this way:
On Error GoTo ErrorHandler
....
code
.........
Exit Function
Error Handler:
if err = 12 Then .....
|
|
|
|
|
That IS what exceptions are for in the first place.
You wrap the part you want into try{..} and catch the errors afterwards. There your routine can ask user for help, rectify things and retry or just return.
OR you can write simply throw; and catch one level higher.
The idea is not to brach on some magic numbers, but on the type of the exception object thrown - you can have a whole battery of catch-handlers after one try, and if you oder them from derived to base, you can fine tune what you catch.
try
{
..
}
catch (const std::myFunny_error& e)
{
..
}
catch (const std::runtime_error& e)
{
..
}
catch (const std::exception& e)
{
..
}
catch (...)
{
}
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Try looking up "structured exception handling" in the MSDN. From what I can see, this lets you catch the access violation.
Another way to get around this problem would be to modify your library interface. Suppose your current routine is like this:
void OperateOnArray(int array[], int array_size);
You could change the interface to something like the following:
void StartOperation();
void SetOperationItem(int index,int item);
void DoOperation()
In this case, the array is managed by your library. StartOperation(); initializes the array to the empty condition. SetOperationItem() sets an item in the array, growing it as necessary. Finally, DoOperation() does the operation the original function OperateOnArray(...) did, except it does it on the array your code is managing. If the caller needs to get the array back as part of the results, you could add a corresponding function like:
void GetOperationResult(int index,int *result);
Software Zen: delete this;
|
|
|
|
|
you might also look at IsBadReadPtr and IsBadWritePtr. as the other poster said, it doesn't stop you from running off the end of the array into other legal, but unrelated, chunks of memory; but it will tell you if you're on your way to an access violation or not.
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
Use std::vector instead of plain arrays, and at() instead of [] .
|
|
|
|