|
Look here[^] for an explanation and sample of the qsort algorithm.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
tnx that did help, but i still do not understant the last parameter...
|
|
|
|
|
It's the comparison routine that qsort() will call several times during the sort, passing pointers to two array elements on each call.
|
|
|
|
|
Does Microsoft ever advocate changing MFC source code ?
If Yes in what case ?
|
|
|
|
|
What? i don't understand your question...
cya !
|
|
|
|
|
I would not change MFC's source code, anyway, we don't really have to it, only some part of it for debugging purpose.
but again, what is the question ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I think it is not a good idea to change MFC library, because it makes your code extremely unportable and maybe unstable.
I think there are several other alternatives like:
1) Derive an object and override some functions
2) Build a new object similar to an MFC object (it is alowed to "learn" by reading MFC source code)
3) Hook some GUI object
4) Etcetera...
Best regards,
Jaime.
|
|
|
|
|
MFC is well tested code, and to the most extent reliable( ignore some of the bugs, because everyone ll do some mistakes). obviously MS encourages you to add extra functionality to the MFC classes by deriving the classes and overriding the classes. It provides the only basic framework. With the standard classes that it provides, its almost impossile to create the look and feel application in the crazy GUI world
VC++ programmer
|
|
|
|
|
Check the headers they say to never edit MFC code.
|
|
|
|
|
I wrote this CTreeCtrl-based control and put it in a .dll
The control consists of a dialog/resource class DIALOG_TREE and a private
tree-manipulating class.
Now to use this control in a app, I create an empty dialog as a placeholder for the control, then I declare a global pointer to the class
DIALOG_TREE* pTreeDialog;]
then in DoDataExchange()
pTreeDialog=new DIALOG_TREE();<br />
pTreeDialog->Create(IDD_DIALOG_TREE,this);<br />
pTreeDialog->SetWindowPos(NULL,x+25,y,cx,cy,SWP_SHOWWINDOW);<br />
pTreeDialog->ShowWindow(SW_SHOW);
There are two problems which I can't seem to be able to solve:
i. I would like to call the control directly (response = pTreeDialog->do Modal())
so I would be able to react. (and maybe dispense with the empty dialog in the app resources)
ii. The tree manipulating class builds a list of items and I can't seem to succeed
passing the list back to the client app.
Any suggestions would be appreciated.
TIA
alex
|
|
|
|
|
Hi everyone,
I need to open CFileDialog window when the root of the folders' tree can be set differently from the Desktop. This way I can require the user to choose a directory from a specific part of the files system.
I tried to look in CFileDialog and haven't found a parameter that can set the folders' root.
If you know how this can be done with CFileDialog or have a code that might help me to implemet this request, please let me know.
Lots of thanks,
Gidi Gal
|
|
|
|
|
CFileDialog has a member m_ofn, which is an OPENFILENAME structure. In that structure, you have to set the lpstrInitialDir variable to point to a string containg the folder in question.
CFileDialog FileDialog(TRUE);
FileDialog.m_ofn.lpstrInitialDir = "C:\\MyDirectory";
FileDialog.DoModal();
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Hi PJ,
Thanks for your reply. I tried it, but it does not set the root directory to be "C:\\MyDirectory",
only the initial displayed directory. This means that the user can choose for example the desktop directory. I'd like to display a directories' tree that its root will be "C:\\MyDirectory" with no possibility for the user to pick directory above it.
Thanks,
Gidi Gal
|
|
|
|
|
Restricting user's choices like that is something I have never done, but I would start by looking at the CFileDialog::OnFolderChange() function (CDN_FOLDERCHANGE notification) and trying to stop the user if they change to a directory out of the root specified. Maybe also handle the OnFileNameChange() and OnFileNameOK() functions.
Good luck
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Hi,
I've written a piece of code that creates 10 threads (CreateThread) that poll 10 Transactional MSMQ message queues using MQReceiveMessage (check the url at the bottom). I've played around with the time out parameter in MQReceiveMessage. At the moment it's set to 5000ms??? (what value do you suggest?).
The same Message Queue code that I've written and I've used in a single threaded application works like lightning. 100,000 x 257 byte long messages are received from a private queue in 30 seconds.
My multithreaded app takes 10 seconds to read 10 messages from 10 transactional queues.
The CPU usage of my app is 99!!!
The core of my thread code follows...
HANDLE hQueue = A Valid Queue Handle - I used MQOpenQueue to open queue the same way the MSDN example at the bottom does it.
char pMessage[4096]; this is a buffer big enough to handle MSMQ messages.
s_msmq_message *in_mess is a structure of the message;
int thisListener is a unique integer [0 to 9] identifying this thread;
int volatile is_continue; This is 1 while my app is running and 0 when the user hits the close button.
HRESULT hr = S_OK;
HANDLE mutexThreadListeners is a global mutex used to sync calls to HandleDataMessage.
DLG is a global pointer to my main dialog. ie. DLG = this;
while(is_continue)
memset(pMessage, 0, sizeof(pMessage));
hr = mq.ReceiveTransactionalMessage(hQueue, pMessage, sizeof(pMessage)); //mq - my MSMQ wrapper
if(hr != S_OK)
{
in_mess = (s_msmq_message*)pMessage;
wait_status = WaitForSingleObject(mutexThreadListeners, INFINITE);
//HandleDataMessage(in_mess, thisListener);
iRecordCount++;
iTotalMessages += 1;
// **** sprintf(strRecordCount, "Processed %d Records", DLG->iTotalMessages);
// **** DLG->m_labelRecordCount.SetWindowText(strRecordCount);
ReleaseMutex(mutexThreadListeners);
}
if(hr == MQ_ERROR_IO_TIMEOUT)
{
TRACE1("\n%sMessage Queue Empty.", strQueueArray[thisListener]);
}
SwitchToThread();
}
What else is really wierd - when I remove the comments from the lines marked with ****, some of my threads wont close. I call WaitForMultipleObjects(10, hThreadListeners, TRUE, INFINITE) in OnClose and my program hangs. If I set WaitForMultipleObjects to time out I get all sorts of nasty access violations.
If I remove these lines, my application closes down like a dream, but it still hogs the CPU!!!
How can I stop these threads from hogging CPU time? And why do the lines marked with **** cause my app not to close properly?
The MSMQ code I use to receive and open queues can be found at...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msmq/msmq_using_reading_msg_6feh.asp[^]
I modified the function to receive a queue handle as a parameter - so I don't open and close the queue for each message.
Please Help, Thanks in advance.
|
|
|
|
|
I've discovered that these threads aren't my problem.
I have one other thread that detects whether a server is either up or down.
I've found a solution for the problem, but I would like some experts to make some suggestions because I know that there must be a better way. There must be a built in Win32 function to solve my problem properly.
This is my problem thread...
int i = 0;
bool bSpxServerStatus = FALSE;
while(app_running)
{
bSpxServerStatus = Check_That_Server_Is_Up();
if(!bSpxServerStatus)
{
Reconnect();
}
/* My HACKED solution */
for(i = 0; i < 55; i++) //The combination of a for loop, Sleep and SwitchToThread solves my problem.
{
SwitchToThread(); //Plain SwitchToThread Doesn't Work
Sleep(55); //Plain Sleep(3000) didn't work either.
}
}
With out my hacked solution my thread hogs all the CPU time. Is there a better way?
I don't need the thread to loop every second. Sleep(3000) doesn't work, and I've read you should never use it. http://www.flounder.com/badprogram.htm#Sleep[^]
Thanks in advance.
|
|
|
|
|
How can you retrieve the HINSTANCE when you only have HWND? what is the method? Thanks in advance.
|
|
|
|
|
hi,
To get hInstance. you can use AfxGetWinApp() sdk function. It retrives hInstance of the application.
thanks & regards
Bharadwaj
|
|
|
|
|
Use GetWindowLong() with the GWL_HINSTANCE flag.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Hi everybody : ). A short question about callbacks in Visual C++. I got a Visual C++ DLL which is called by a VB Application. The Visual C++ DLL is passed the address of the outside callback function using a local function in it, like this:
<br />
void SetCallbackRoutine(long ExternalAddress)<br />
{<br />
ptrCallbackRoutine = ExternalAddress;<br />
}<br />
ptrCallbackRoutine is declared like this:
<br />
#pragma bss_seg("DLLShare")<br />
long ptrCallbackRoutine;<br />
#pragma bss_seg()<br />
Now... ptrCallbackRoutine memorizes its data fine. The address is ok. When I try to callback my original VB function from the SetCallbackRoutine that I already written above, it works. This works:
<br />
void SetCallbackRoutine(long ExternalAddress)<br />
{<br />
ptrCallbackRoutine = ExternalAddress;<br />
<br />
typedef void (__stdcall *OutsideFunction)(BSTR stringVar);<br />
OutsideFunction FunctionCall;<br />
FunctionCall = (OutsideFunction)ptrCallbackRoutine;<br />
BSTR temp = ChartoBSTR("Testing");<br />
FunctionCall(SysAllocString(temp));<br />
}<br />
However, when I try to do this from within a TimerProc, it crashes. This crashes:
<br />
VOID CALLBACK TmrProc (HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)<br />
{<br />
KillTimer(NULL, ctTimerID);<br />
<br />
typedef void (__stdcall *OutsideFunction)(BSTR stringVar);<br />
OutsideFunction FunctionCall;<br />
FunctionCall = (OutsideFunction)ptrCallbackRoutine;<br />
BSTR temp = ChartoBSTR("Testing");<br />
FunctionCall(SysAllocString(temp));<br />
}<br />
It's not about KillTimer. I also tried without that instruction and it still doesn't work.
I suppose that the DLL cannot call a function from VB whenever it wants? It can only call it at particular time during execution?? How can I work around this? Is there any way that I can call back on the VB function at any given time??
Thank you for your help : ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Hi,
What does ChartoBSTR do? Where does the returned pointer point to?
Can you post the function.
Cheers
|
|
|
|
|
Oh. ChartoBSTR is a simple function that does the said conversion. I copy pasted it into my Application. It has nothing to do with the problem, since in one function it works and in other function of the same file, it crashes. It's not about this function. I also tried without it, just making up some dummy string. And I got the same behavior.
With or without that function, calling back my VB function works from in the first case, and doesn't work in the second case. So... I'm kind of puzzled . Could it be that I can't call a VB function unless I called from VB first?
Since in the first case, I call a Visual C++ function, that, in turn, calls my function from VB. This works. But if I want to call the function from VB from that TimerProc (or from anywhere else for that matter), it doesn't work. I tried calling this from a HookProc too... if I do that, the process that contains the hook crashes. Grrrr : ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
I was taking a long shot there.
I thought a possibility was that ChartoBSTR was returning a pointer to a local variable that gets removed from the stack when the function returns.
This might cause your code to crash some times and work other times.
Good luck
|
|
|
|
|
Hm... so... any other ideas? Anybody??? : )
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas wrote:
ChartoBSTR
HI Axonn ,
What about using T2BSTR() defined in ATLCONV.h or CComBSTR("helloo").Detach().
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|