|
Hi,
Will this Suffice , then implement the callback
// call the functions: First sort with name
qsort(qsortdata, count, sizeof(struct Person), qsort_callbackName);
// then sort the required ones age etc
qsort(qsortdata, count-noidfiles, sizeof(struct Person), qsort_callbackAge);
(IMHO)
Regards,
FarPointer
-- modified at 13:06 Friday 31st March, 2006
|
|
|
|
|
What do you mean by this in the second sort? count-noidfiles
|
|
|
|
|
Well what iam actually doing is that first i will sort with respect to the name ,then sort the sorteddata with respect to the age .
int qsort_callback(const void * first, const void * second)<br />
{<br />
struct person *p1, * p2;<br />
p1 = (struct person *)first;<br />
p2 = (struct person *)second;<br />
if( (*(p1->Name)).Compare(*(p2->Name)) >0 )<br />
{<br />
if(p1->Age > p2->Age)<br />
return 1;<br />
if(p1->Age < p2->Age)<br />
return -1; <br />
}<br />
<br />
}
// Well here i have tried to make sorting in one go as David says qsort is not stable one but the previous one is more logical clear ,like if later we need a more customization on the sort you again sort on the sorted data
Regards,
FarPointer
-- modified at 13:20 Friday 31st March, 2006
|
|
|
|
|
FarPointer wrote: ...but the previous one is more logical clear ,like if later we need a more customization on the sort you again sort on the sorted data
For reasons already mentioned, calling qsort() again on the sorted list using a different key will not work.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
FarPointer wrote: Will this Suffice
No, because qsort() is not a stable sort. You would need to combine the effects of qsort_callbackName() and qsort_callbackAge() and call qsort() only once.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Wat do you mean by not a stable sort ,it should be a well tested and implemented one right(IMHO).
Regards,
FarPointer
|
|
|
|
|
Stable sorting algorithms maintain the relative order of records with equal keys. If whenever there are two records A and B with the same key and with A appearing before B in the original list, A will appear before B in the sorted list, the algorithm is said to be stable.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Well thanks for making it clear .
Regards,
FarPointer
|
|
|
|
|
|
David
Can you show me an example?
|
|
|
|
|
int bynameinage( const void * v1, const void * v2 )
{
pmyData data1 = *(pmyData *) v1;
pmyData data2 = *(pmyData *) v2;
int dt = data1->age - data2->age;
if (dt != 0)
return dt;
return _tcscmp(data1->name, data2->name);
}
...
qsort(..., bynameinage);
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Neat and Clean.
Regards,
FarPointer
|
|
|
|
|
Probably a fairly common problem, but I'm having difficulty getting precisely the answer I need, so I'm asking a different way.
I have an MFC class (actually a dialog) in my app that I need to shift out to a DLL. There's a major product rearchitecture looming, so this is a short-term problem I need to solve. It doesn't have to be pretty, but it does need to be quick to implement.
Of course, to make my life difficult, the DLL will need to call a couple of class methods from back in the app. A typical example would be the dialog in the DLL has a Help button that, when pressed, launches a Help() method back in the app.
I'm thinking I make a "Callback" class, which exposes only the methods I need. The app creates one of these and sets up the "inside" objects it needs to know about, and the DLL itself only needs to know about this callback class. Is this the right approach?
At this point I'm stuck. I know I'm trying to hack a solution to a bad early design decision, but luckily this is only short term (but needs to be done).
Like I say, I've searched but so far haven't found any example code that deals with this specifically. Lots of "generic" stuff that mostly talks about C functions and "mentions" class callbacks. I could use a nudge in the right direction.
Brad.
|
|
|
|
|
Why not create an instance of the class and pass it to your dll?
|
|
|
|
|
That was rather the approach I was thinking of. But the class (let's call it CCallback) needs to have knowledge of a fair amount of the main app (ie. the implementation of CCallback requires a fair number of #includes from other app classes that the DLL need not know about).
I might just not be looking at this from the right angle (I've been dealing with COM stuff for so long that I've probably lost sight of the basics). But I have my CCallback.h, which I #include in the DLL code so it knows what my class looks like. That's fine for compiling, but the linker complains about all the unresolved externals.
|
|
|
|
|
Do you have your lib for your dll linked into the app?
|
|
|
|
|
Yes. It's actually the DLL linking that's complaining. So I think I'm just not declaring my CCallback class correctly *within* the DLL code. Once I can get the DLL to understand how to call back, then I can work on getting my app to actually call into the DLL (I haven't even go there yet, probably doing this backwards).
|
|
|
|
|
You might need to app the .cpp to your dll project
|
|
|
|
|
Which has intimate knowledge of the app classes, which the DLL doesn't want to know about. So it'll never compile.
|
|
|
|
|
Yeah looks like callbacks might be the way to go.
|
|
|
|
|
Okay great. Now that we've established that, I'm stumped as to *how* to do a callback to a class in my main app from the DLL. Any sample code covering this would be extremely helpful.
Brad.
|
|
|
|
|
Hi ihave the following code
#include <afxole.h>
#include <afxwin.h>
#include <_dbdao.h>
#include <stdio.h>
void main()
{
}
I am getting the following errors
error C2079: 'CdbBSTR' uses undefined class 'DLLEXPORT'
c:\program files\microsoft sdk\include\_dbdao.h(77) : error C2239: unexpected token '{' following declaration of 'CdbBSTR'
c:\program files\microsoft sdk\include\_dbdao.h(95) : error C2146: syntax error : missing ';' before identifier 'CdbVariant'
Please can some one help me solve this issue
JK
|
|
|
|
|
netsharq wrote: #include <_dbdao.h>
Include dbdao.h instead.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Getting the same error, but now number of erros have become more as
rror LNK2001: unresolved external symbol "public: __thiscall CdbBSTR::CdbBSTR(unsigned short *)" (??0CdbBSTR@@QAE@PAG@Z)
MFCExtnDLL.obj : error LNK2001: unresolved external symbol "public: struct IUnknown * __thiscall CdbOleObject::GetInterface(int,int)const " (?GetInterface@CdbOleObject@@QBEPAUIUnknown@@HH@Z)
MFCExtnDLL.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CdbOleObject::OnInterfaceChange(void)" (?OnInterfaceChange@CdbOleObject@@UAEXXZ)
MFCExtnDLL.obj : error LNK2001: unresolved external symbol "public: __thiscall CdbOleObject::CdbOleObject(void)" (??0CdbOleObject@@QAE@XZ)
MFCExtnDLL.obj : error LNK2001: unresolved external symbol "public: class CdbOleObject & __thiscall CdbOleObject::operator=(class CdbOleObject &)" (??4CdbOleObject@@QAEAAV0@AAV0@@Z)
MFCExtnDLL.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CdbOleObject::~CdbOleObject(void)" (??1CdbOleObject@@UAE@XZ)
MFCExtnDLL.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CdbStaticCollection::Refresh(void)" (?Refresh@CdbStaticCollection@@UAEXXZ)
MFCExtnDLL.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CdbStaticCollection::
|
|
|
|
|
netsharq wrote: Getting the same error...
Actually you're not. Linker errors are hardly the same as compiler errors. You need to link with the appropriate DAO library (e.g., ddao35.lib).
See here.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|