11-17-2010 04:18 AM
- Load the XMLSample (toolbox\XMLSample.cws)
- Add [CVIDIR]\sdk\lib\msvc\ComDlg32.Lib
- Replace the XMLSample.uir and XMLSample.c with the ones from the attachement
This works under XP but not under Windows 7 (32 bit home professional):
When running click PRT (works), then load a XML, then try the PRT button again (crashes).
I first used PrintDlg when it crashed, but PrintDlgEx doesn't work either.
Can anyone verify this, please? I have only one Win 7 box at hand.
Solved! Go to Solution.
11-17-2010 10:41 AM
I was able to reproduce the crash. It's probably happening because the PrintDlg function uses COM and it must require the thread to be initialized as apartment-threaded. And by default, the XML driver (via the CVI ActiveX Library) will initialize it differently, unless it's already been initialized.
The crash goes away if you initialize the thread yourself, before calling any of the XML functions:
CA_InitActiveXThreadStyleForCurrentThread (NULL, COINIT_APARTMENTTHREADED);
Luis
11-18-2010 01:43 AM
CA_InitActiveXThreadStyleForCurrentThread (NULL, COINIT_APARTMENTTHREADED); only works for the current thread, it will be tricky (maybe next to impossible) to do...11-18-2010 02:01 AM
Another interesting bit: if you use PrintDlg and pass hwndOwner=NULL it doesn't crash. This doesn't work with PrintDlgEx since it requires a valid hwndOwner.
11-18-2010 11:55 AM - edited 11-18-2010 11:56 AM
1) I can't tell you why this changed in Windows 7. It has to do with the internals of the PrintDlg function, which I'm not privy to.
2) While it's true that CA_InitActiveXThreadStyleForCurrentThread only sets the threading model for the current thread, there's no reason why you can't also call that function from additional threads. You just have to make sure that each thread is initialized correctly. And note that you don't even have to call it from each thread that might print. You just have to call it from each thread that both calls the XML driver and prints.
Luis