|
Hi ashish,
Your function shouldn't cast to AfxGetMainWnd(), you should pass the this ptr to AfxGetMainWnd(). Your thread may work now, but that's only because this is probably a dialog based app where CReadIntoSybaseDlg happens to be your main window (AfxGetMainWnd() is returning a ptr to an actual CReadIntoSybaseDlg). You always want to know what parameter you're passing to your thread function, and AfxGetMainWnd isn't going to return a known type if you ever wanted to use this code in another program.
I don't have much experience w/ CDaoDatabase to know what the exact problem might be, but I suspect that maybe you're opening the record set in your worker thread, and moving through the record set in your main thread(or a similar scenario). If that's the case try to ensure that all access to the database related objects are taking place in the same thread because I suspect that CDaoDatabase doesn't like it if you're doing things from multiple threads. It's conceivable that MFC/CDaoDatabase is attaching itself to a CWnd object in your main thread since that's where it's probably being instantiated from. If MFC is attached to a CWnd in your main thread, and your main thread is blocking while waiting for a worker thread to finish something w/ the database, you could see a lockup condition.
Best advice would to be sure to do all your database accessing from the same thread that's using the db objects. Try doing all the processing in your main thread, and then try it again so that all the processing in the worker thread to see if it behaves differently.
Btw, Do you really need a worker thread for what you're trying to do? I use Sybase & I don't find the queries to take that long.
If you're designing your app so that the UI thread displays data when the worker thread signals that data is ready & your accessing the same db objects, & if CDaoDatabase really has an issue w/ being used this way, it's going to cause you to have to do some extra work.
-Wes
Sonork ID 100.14017 wtheronjones
|
|
|
|
|
Wes
Thanks for the advice. I will make the appropriate changes.
You may be right about CDaoDatabase. I am opening it in the main thread (Open call) and then passing the main processing function to AfxBeginThread so that all the processing (multiple databases are being used) can be done in the background. The reason I have to use two threads is that I need GUI control over the dialog window.
I read some of the DAO documentation and it does not support multiple threads. However, I had thought if I did everything in the worker thread, it should be OK. Apparently, it does not like being opened with the main thread and then being worked on by another. I will probably have to move the code around.
Thanks a lot
ashish
|
|
|
|
|
Wes,
On another note, since you mentioned you are using Sybase, I too am using Sybase but with the MFC ODBC classes. It is too slow, especially with inserts and updates. Any hints?
Thanks
ashish
|
|
|
|
|
Hey,
I don't find the ODBC to be slow at all for inserts & updates... I am using more of the ODBC API instead of CDatabase, but that's cause most of my classes work w/ CE (no CDatabase on CE). There are some things you can do to increase performance such as not using CRecordset::AddNew() and then CRecordst::Update to insert a new row. If you know the values, just write an insert statement... it's only one trip to the database instead of two, (unless you need retrieve the new primary key). If you're doing more than a certain # of inserts to the same table(a batch operation let's say), it's best to use a prepared statement & bound parameters at more of an API level than to use a bunch of single insert statements or using AddNew/Update. Just guessing, but i'd think that the odbc classes will be faster than the dao classes.
-Wes
Sonork ID 100.14017 wtheronjones
|
|
|
|
|
I meant the ODBC interface in MFC implemented through CDatabase. I find that to be slow. But its only slow with Sybase and not with SQL Server, which is my other data source.
thanks
ashish
|
|
|
|
|
In VS6 you could see a live memory-dump in a window. I can't find this feature in VC7. Is it left and hidden, or removed?
|
|
|
|
|
Debug -> Windows -> Memory -> pick on of 4 windows
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
I am converting a UNIX application to Windows using VC++ and MFC. There are a large number of printf statements in the code, so I re-defined the printf function, with vsprintf, so that all text will go to a richedit control.
The problem I face is that when a data file is read, it is possible that one of the fields will have a "%" sign as part of its value. When this value is displayed, it looks as though vsprintf is behaving as documented and printing the value without the % sign. Does anyone know of an easy, efficient way to make sure the % sign is printed as well?
Thanks,
Shawn
|
|
|
|
|
Shawn Horton wrote:
Does anyone know of an easy, efficient way to make sure the % sign is printed as well?
I'm not sure what exactly do you want to achieve. You've mentioned that there are fields in data file and vsprintf replaces % sequences with actual values. Do you want to keep a percent sign before the value? If this is the case, try appending %% in front - this will result in one percent sign being printed.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Maybe this will help:
char data_name[DATANAMELEN];
read_function(data_name);
//data_name now contains the value "%recovered"
printf("we read in %s", data_name);
The printf statement to the Richedit window is now
we read in recovered
notice the missing %?
Maybe that is a bit clearer.
My hope is that I will not have to look for a % in character in each variable, and then insert a % in front of that.
Thanks for the help.
|
|
|
|
|
Shawn Horton wrote:
Maybe that is a bit clearer.
Totally clear now. I don't know about any format modifier which could cause [v]sprintf to literally copy % sign.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
I should just post something like "Duh I am having a problem" on my first post, because the second one usually makes more sense.
|
|
|
|
|
If you're using MFC in your project, use CString::Format - it will work for you.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Sounds like a bug in vsprintf
It surely should take everything that is passed literally as literals.
Or I am missing something here?
Maybe it is a feature, called somewhat like "recursive format substitution"...
What happens if you replace "%" with "%%" in your data_name?
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Actually, it was a bug in our re-defined printf. The function for the richedit control that we were using was expecting both a format specifier and a va_list, but we forgot the format specifier. Thus, when the function saw
%recovered, it saw an invalid format specifier (%r) and threw out the % like it said it would.
I hate when compilers do what you tell them to do instead of doing what you want them to do.
Thanks for the help.
Shawn
|
|
|
|
|
Shawn Horton wrote:
I hate when compilers do what you tell them to do instead of doing what you want them to do.
Yeah... After 40 years of science, computers are still stupid at all. Tons of work remaining for us developer folks
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
I get this error when using acmDriverEnum to enumerate all the different codecs on my system, this is the callback function:
BOOL WINAPI listCallback(HACMDRIVERID hadid, DWORD dwInstance, DWORD fdwSupport)
{
if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CODEC)
{
ACMDRIVERDETAILS details;
details.cbStruct = sizeof(details);
acmDriverDetails(hadid, &details, NULL);
SendMessage(GetDlgItem(ghWnd, IDC_CODECS), LB_INSERTSTRING, 0, (LPARAM)details.szLongName);
}
return true;
}
In this routine i simply check if the current driver is a codec, and if it is i add the name of it to a listbox. The error happens when i have looped though all of the different codecs and the return true; statement has been executed. After that it jumps to some assembly code, and this is the stament it gives me the message after completing:
call dword ptr [ebp+8]
When that statement has been executed, the "User breakpoint called from code at 0x77f9f9df" message appears, and it jumps to this statement:
int 3
I've never experienced this message before and i haven't got a clue what it means.
All help appreciated.
-Rune Svendsen
|
|
|
|
|
This is an exception being thrown... Try review the call stack and get some other clues...
Concussus surgo.
When struck I rise.
|
|
|
|
|
Sorry for my ignorance, but what is the call stack and how to i review it?
Thanks.
|
|
|
|
|
Try View/Debug Windows/Call Stack (or press Alt+7)
It's a debug window that shows all the functions called until your program got into that line the debugger is showing.
Concussus surgo.
When struck I rise.
|
|
|
|
|
umm, not sure if it makes much sense, but this is the contens of it when the message appears:
NTDLL! 77f9f9df()
NTDLL! 77fb4966()
NTDLL! 77fb3bdc()
NTDLL! 77fa7131()
NTDLL! 77fca4cb()
MSMS001! 01ac7b68()
MSMS001! 01ac7539()
MSMS001! 01abfcf7()
VCT3216! 01254326()
|
|
|
|
|
The message "User breakpoint called from code at 0x77f9f9df" means that a software interrupt 3 was thrown, which is used for breakpoints. An int 3 asm instruction is a so called "hardcoded breakpoint" and causes the message and halts the program in the debugger. In debug mode the compiler initializes any unused memory and also some bytes before and after every function with this instruction. This is a good thing, because it let you find jumps to invalid adresses, and obviously such an illegal jump is also your problem.
Okay, so much about the magic things in the background. What actually happens in your case is a bit difficult to figure out. I assume that the stack is not layed out as it should, therefore the app crashes while executing the return statement. Note: The return statement is only the position it crashes - the real problem is somewhere else and just not detected before.
Please do the following:
- What happens if you remove anything from your function, but the
return true statement? Is the problem still there? - Please show us the line you where you pass the callback function to acmDriverEnum(). Are you doing some ugly cast's there because otherwise it would not compile? Maybe your callback functions prototype is not layed out as it should. Casting it to the "correct type" is a typical source for big trouble, if you are not absolutely sure about what you are doing.
(I really do have a feeling that it is 2. that causes your problem - but hey, it's just a feeling )
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
1. I have tried removing everything from the callback function except return true; , and when i do that the messagebox doesn't appear, but in the Debug fan (the one where there's Build, Debug, Find In Files 1 etc.) it says
First-chance exception in MP3.exe (MSACM32.DLL): 0xC0000005: Access Violation.
First-chance exception in MP3.exe (MSACM32.DLL): 0xC0000005: Access Violation.
(yes, the statement is shown twice)
2. The line where i call the function that uses the callback function is as follows:
acmDriverEnum(listCallback, NULL, ACM_DRIVERENUMF_DISABLED);
The prototype of the callback is:
BOOL WINAPI listCallback (HACMDRIVERID hadid, DWORD dwInstance, DWORD fdwSupport); but that is actually not the original callback function definition, it's like this:
BOOL ACMDRIVERENUMCB acmDriverEnumCallback(HACMDRIVERID hadid, DWORD dwInstance, DWORD fdwSupport); the reason i changed it was that it wouldn't compile when i used ACMDRIVERENUMCB, a lot of compile errors showed. so i asked what could be wrong and one said that maby ACMDRIVERENUMCB was just a typedef of WINAPI so i used that, could that be where the problem lies?
Thanks for your help.
|
|
|
|
|
redeemer wrote:
the reason i changed it was that it wouldn't compile when i used ACMDRIVERENUMCB, a lot of compile errors showed. so i asked what could be wrong and one said that maby ACMDRIVERENUMCB was just a typedef of WINAPI so i used that, could that be where the problem lies?
I doubt it. (Maybe this is just because it was me who suggested you to change it . However, I never said is a typdef for WINAPI, but it is a typedef for the pointer to listCallback. Take a look at the definition of ACMDRIVERENUMCB in the header file. The docs are just wrong here.)
However, back to your problem: It works if you remove all code from your listCallback. Therefore it is probable (but not sure...) that the problem is caused by that code. (The exception messages you get are no problem. If the debugger does not claim about an unhandled exception they are catched inside MSACM32.DLL - nothing you should worry about.)
Next step: Trackle it down. If it fails because of that code, check which part of the code (especially the calls to acmDriverDetails() and/or SendMessage()) causes the problem. (Don't forget to pass a valid string in SendMessage() if you remove the call to acmDriverDetails()!)
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Hi!
I want to get the text of a button from another app.
Usually I use SendMessage with WM_GETTEXT to get the text. But this time it doesn't work because the button has a bitmap AND a caption.
Even Spy++ can't get the text of the button.
It seems like the caption is being drawn at runtime onto the button
Does anyone know a solution?
thanks in advance
modified 12-Sep-18 21:01pm.
|
|
|
|