|
Huh?
What's the duplicate post for?
Nish
One little CD gone,
Then two CDs gone,
Then 5 more gone,
For a total 7 gones,
If I was a CD R,
I'd wanna cry,
Cause I'd be just a goner,
For a nasty CD burner.
[funny how frustration wakes up the poet in me]
|
|
|
|
|
Unfortunately, all you can do is manually trigger the handler whenever you change the selection. If this is something you need to do a lot, you might want to consider making a custom combo box class, otherwise you'll just have to live with it.
--------
Sip my mind.
|
|
|
|
|
Any idea why this message map would crash my program (sometimes exit without crashing) only in release mode, not in debug mode
ON_COMMAND_RANGE(1001, 6999, OnButtonClick)
Even if I declare OnButtonClick to be empty like so:
OnButtonClick(WPARAM wParam, LPARAM lParam) {}
It crashes as soon as I click one of the dynamically created buttons with an ID in that range.
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|
|
handlers for ON_COMMAND_RANGE only take a single UINT parameter.
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND_RANGE(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3, OnFileMenuItems)
END_MESSAGE_MAP()
void CMainFrame::OnFileMenuItems(UINT nID)
{
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
submenu->CheckMenuRadioItem(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3,
nID, MF_BYCOMMAND);
}
-c
Conscience is what hurts when everything else feels good.
Smaller Animals Software, Inc.
|
|
|
|
|
Thanks a ton. I dunno where I got those params from.
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|
|
those params are what you use when you do an ON_MESSAGE handler.
-c
Conscience is what hurts when everything else feels good.
Smaller Animals Software, Inc.
|
|
|
|
|
Found this in MSDN "The COM Programmer's Cookbook". It is a #define to find an instance pointer from an interface in vanilla C.
#define IMPL(class, member, pointer) \
(&((class *)0)->member == pointer, ((class *) (((long) pointer) - offsetof (class, member))))
What I have some difficulties understanding is the cast (&((class *)0) . What exactly does that do here?
Thanks
/moliate
|
|
|
|
|
It casts the pointer returned to be the type that is passed in by the class variable, because it is first cast to long for a subtraction. Presumably it is that type of pointer to start with.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
I´m feeling really stupid here, but I still don´t get it. The problem is still the first comma expression. If the interface is the first in a struct, would it not compile down to 0 , leaving a nasty null pointer exception? And what will the result be for the == operation if class->member does not equal pointer ? And isn't the pointer returned the one in the second comma expression?
I really want to understand this, but I have only used commas in simple for-loops before...
/moliate
|
|
|
|
|
#define IMPL(class, member, pointer) \ (&((class *)0)->member == pointer, ((class *) (((long) pointer) - offsetof (class, member))))
I saw the first bit the first time around and didn't think about it much, but it certainly seems to me that it's trying to dereference a NULL pointer and access a member of it, ( before checking if the address of the member == the pointer ), which surely should crash ?
Where is this used ? Where does it come from ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Basically it is a manipulation in "C" in order to get what we have in C++ where classes are concerned. It looks like IMPL is a way to get the this pointer from an interface pointer.
(&((class *)0)->member == pointer
The NULL pointer is first converted to pointer that is the desired type, and this pointer is compared to the input pointer. If this comparison was not between two pointers that had a typesafe cast, the compiler would throw an error at this point in the compilation.
(&((class *)0)->member == pointer , ((class *) (((long) pointer) - offsetof (class, member))))
The key to this macro, is the comma after the comparison test, this basically throws away the result of the comparison, the compiler will see this, and consequently throw away this comparison test in the final compiled code. Then the rest of the macro is used to calculate the offset to the instance data for the struct.
So in short, that comparison is a typesafe cast check in "C", that is performed competely at compile time.
Hope this helps!
Checkout my Guide to Win32 Paint for Intermediates
|
|
|
|
|
kilowatt wrote:
If this comparison was not between two pointers that had a typesafe cast, the compiler would throw an error at this point in the compilation.
[Scchluug] <= Sound of synapses connecting.
Great explanation! Thanks!
/moliate
|
|
|
|
|
Hi.
I havent' really started any .net programming, but i was wondering, is it possible to program the gui using .net extensions (making it easier to program?), but being allowed to program the rest of the code so that it compiles to assembler and hence does not lose any speed (my main reason for using C++)?
I'm only asking because i've got the impression that gui programming using .net is a lot easier then in mfc.
|
|
|
|
|
No. At least not easily. I believe you can still use COM and therefore access C++ compiled code that way, but if you use C++ in .NET you would generally use managed C++ and still compile to the CLR.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
How can I capture a video from a capture device and writing it to a mpeg file.
sorry for me english!
|
|
|
|
|
LoadImage works great for me on most systems and on most bitmaps EXCEPT for
on XP, 2000 & NT, I can't get RLE compressed bitmaps to load!
ALSO is there any info on getting JPEGs to be loaded as well???
Thanks for any help
|
|
|
|
|
Clifford Hall wrote:
ALSO is there any info on getting JPEGs to be loaded as well???
Read the FAQ.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
I'm am just starting to learn Visual C++ and I'm having difficulties understanding how to implement certain concepts. What I'm trying understand is how a veiw/doc program works, especially how to transfer information from a modal dialog box created in a view section to a CArray in a Document section. I'm also having problems on how to use a spin control and list box in a dialog box.
Does anyone have a very basic demo program that will show me how to get information between these sections (doc and view) and how to use some of the basic features of a dialog box (ie list box, spin control, etc)?
Thanks
Ed
|
|
|
|
|
First of all, you'll find long term that std::Vector is a much better container than CArray, which was written only to be used while the STL was finalised. Check out my STL 101 articles for more info.
Secondly, the way to get info out of a modal dialog is to stuff it out of the controls ( which are destroyed ) into a container ( CArray or vector are fine ) and then read that from the dialog object after the modal loop has ended. The variables continue to exist, but the windows (controls) have been desroyed.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Where can I find your STL 101 articles?
Which is better for intensive number crunching? (Vectors or Carray)
Can a vector hold a custom structure?
|
|
|
|
|
In the STL section.
I tried this yesterday with no success, but hopefully here is a link to my vector article, which is at http://www.codeproject.com/vcpp/stl/STL101.asp (just in case it didn't work again ).
ed1 wrote:
Which is better for intensive number crunching? (Vectors or Carray)
Vector, only because the STL comes with a ton of algorithms, which have been written to be as optimised as possible.
ed1 wrote:
Can a vector hold a custom structure?
Absolutely, but you'll need to read my article on function objects to see how to use custom objects with the algorithms. Of course CArray has no algorithms at all, so it's hardly a bad thing, in fact you'll find it amazingly powerful.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
There are some good posts here on the board, but nothing really answers my question.
Say I have an object foo, and a function called DoSomethingWithFoo( IDispatch** val ), it seems a bit of a pain to have to use the IDispatch interface when I would like to just pass the object in. Sureley there is an easy way? To make this clearer:
I have a pointer MyFoo*. I want to call a method bar, which does something with foo objects. Unfortunateley, we only have a bar( IDispatch* ). It seems a pain to pass in an IDispatch pointer, then to use idispatch->Invoke, simply to call the method I want, especially when I have lots of methods to call-
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&df=6&app=50&tid=82458&select=82458#xx82482xx
If this isnt clear please say-!
Thanks in advance
MO
|
|
|
|
|
If I understand you well:
IDispatch *pD;
MyFoo *pMf;
pMf->QueryInterface(IID_IDispatch, &pD);
Bar(pD);
pD->Release();
If this is not the answer you're looking for, please explain a little more.
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
Im not sure if thats what Im after, although Im experiemting now.... ill put it another way:
I have:
Member *myMember;
and a function:
MyClass::getMemberDetails( idispatch **val )
It would be cool if I could just go:
myClassObj.getMemberDetails( &myMember )
But instead I have to do this:
IDispatch *d;
myClassObj.getMemberDetails( &d )
So now the IDispatch item is pointing to the object I want, nameley a Member.
However, to invoke member funcitons on this new member, I have to use IDispatch::invoke, and all of the things which go with it (which I discovered on another post.) Id love to avoid doing all of this....
Hope thats clearer - and your help is much apprecaited on this!!!
|
|
|
|
|
Can you post a code sample? I'm not exactly sure what you asking. Is MyFoo* an interface, or more precisely a pointer to an interface or just a pointer to an instance of a concrete class?
|
|
|
|