VC++ application - use TaskDialog with fallback for Windows XP - visual-c++

I want to use the task dialog in my VC++ application. I am able to create a task dialog successfully using either TaskDialog or TaskDialogIndirect, and it works fine in Vista. However, I want my application to work on windows XP as well, and since windows XP does not support Task Dialog, I have created a dialog of my own that I want to use instead in case the OS is XP.
So my code does something like:
if OS is Vista or higher:
Show TaskDialog
else
Show my own dialog
Now the application still does not work in windows XP. When I attempt to start the application on XP, I get the error "The ordinal 345 could not be located in the dynamic link library comctl32.dll".
This is possibly because the call to TaskDialogIndirect is there in my code, though the call is in an if block. While loading the application it attempts to locate the function in the comctl32.dll, and it does not find it since it is the XP version of the dll.
So my question is:
How do I code my application so that it runs successfully on both XP and Vista, and in case of XP show my own dialog box whereas in case of Vista and higher show the task dialog?

The problem is that your application has a dependency on those functions, a dependency that the OS loader tries to resolve at application start-up. But of course, those functions don't exist in XP, so the executable fails to load.
There are two ways around this. First, try delay-loading comctl32.dll. This should remove the load-time dependency and delay the resolution until the function is actually called. Then you just need to take care not to call it where it's not supported.
If that doesn't work, then you would have to bind to TaskDialog explicitly, via LoadLibrary and GetProcAddress. This way, you never explicitly mention the function in a way that the linker would know about, so you don't take a load-time dependency on it. That's a bit more work though, mucking around with function pointers.

Related

Attaching MSVC 2012 profiler hangs the application

I have a C++ application (it's built using Qt 5.8 library and works with PostgreSQL 9.5 database in case it's relevant). The application is build by MSVC 2012 compiler, is 64-bit application and both debug and release versions run normally on their own and under cdb debugger.
When I try to profile the running application by Visual Studio instrument (Analyze -> Profiler -> Attach), it seemingly hangs as soon as it tries to do something meaningful: simply resizing a window or clicking on checkboxes works, but any attempt to compute new values and write them to database never succeeds, as if control flow didn't return from some call.
When I stop the profiling, Studio marks as a "hot path" sequence of calls RtlWalkFrameChain->RtlpWalkFrameChain->RtlpLookupFunctionEntryForStackWalks->RtlLookupFunctionTable->RtlAcquireSRWLockShared.
RtlpWalkFrameChain has the biggest "exclusive samples" count.
Trying to filter data to exclude initial several seconds of run (until the apparent freeze) results in "No Call Tree Data Is Available" message.
I didn't manage to find any article or post with a similar problem.
The project is build in Qt Creator (I don't have a project file Studio would understand, so I can't run "normal" performance analysis).
OS is Windows 7, exact version of Visual Studio is 11.0.61219.00 Update 5.
Any idea on the subject would be welcome.
Upd: When I try to profile the application with Luke Stackwalker profiler, it aborts with the message ERROR: StackWalk64-Endless-Callstack!. The only relevant comment about the message I found is this Stackoverflow question. When I run application under cdb debugger and then try to profile it with Luke Stackwalker, the error message is the same, but subsequent pause in the debugger shows the proper (or at least believable) stack for all threads. For the working thread debugger points to a line of code inside system library and doesn't advance no matter what I do (once again, without profiling attempts the application runs normally, debugger or not).

JavaFX crashes X Server

Background/Context:
I'm currently developing a touch screen application which is aimed to run on Linux. As a development framework I chose JavaFX (jdk1.7.0_10) due to its rapid prototyping easiness. I'm using Arch Linux (kernel 3.6.10-1-ARCH) distribution and since JavaFX needs a head-full environment to run, I installed Xorg on top of the base configuration. Even thought I'm able to run my JavaFX application, I have some issues with popup windows that are being displayed in my application.
When trying to display those popup windows, sometimes they don't respond as expected or event worse, they crash my application. The error I get is the following:
The program 'java' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadDrawable (invalid Pixmap or Window parameter)'.
(Details: serial 51101 error_code 9 request_code 62 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
By the way, when running the same application on Windows (my development machine), everything works fine.
I also tried to run a composite manager ('xcompmgr') since i was also getting some warnings like
Can't create transparent stage, because your screen doesn't support alpha channel. You need to enable XComposite extension.
but it didn't helped.
Question:
Am i missing some files or configurations in order to run smoothly JavaFX in Linux, or has any one encountered the same challenge? Since my main concern is performance (due to limited hardware specs), I don't want to install a full featured Linux distribution. I only need to run my JavaFX application.
Try running JavaFX in software rendering mode: java -Dprism.order=j2d -jar your.jar
Also note that your platforms seems to be not included into list of supported ones: http://www.oracle.com/technetwork/java/javafx/downloads/supportedconfigurations-1506746.html

Starting a 64bit process from a 32bit app?

I have a WPF 4.0 application that I have compiled for x86. When running on 64bit Win7, I need to start up an on-screen keyboard, located in %windows%/System32/osk.exe. Problem is I can't do it- I get an error 'Could not start On-Screen Keyboard'.
I found this thread:
Unable to launch onscreen keyboard (osk.exe) from a 32-bit process on Win7 x64 which sounds exactly like my problem.
I used all the relevant bits from that post, but the error persists. And even worse, I managed to get a 32 bit version of osk.exe and when I try to start THAT I just get a blank error box- no message at all, just a red 'X'.
So I can't compile my app for AnyCPU (3rd party interop libs), and have read that that might not solve the issue anyways. I have also read that one workaround is to disable virtualization using Wow64DisableWow64FsRedirection, but that this is unsafe. Seems like a lot of effort just to run a little app :(
What can I do to launch this little thing from my app?
Wrapping the offending app in a exe compiled with AnyCPU works fine and seems to be the least painful approach.

Converting Windows App written on XP to Windows 7

I inherited a huge code base which was written to work on Windows XP. Now we would like to migrate to Windows 7. I do not know what is the proper way to go about this. What is the proper approach to do the above task? I did some googling on differences between XP and Windows 7 but I do not get any proper links which describe how the internals of 7 differ from XP. Any links will be appreciated.
Usually how do S/W developers migrate their code/apps written for one version of OS say Vista to Windows 7?
I sell an autoupdate solution (AutoUpdate+, minor plug) and so have lots of experience porting Windows apps to the latest releases, and yet still maintaining backwards compatibility. Porting from Windows XP to Windows 7 can be a big challenge (there should be almost no difference in a move from Windows Vista to Window 7).
Window XP doesn't care where your application exists, and hence programmers would dump both their application and support logic (log files, config files, user profiles etc.) into the same location under "C:\Program Files\". Take this application to Windows 7 and you'll start finding some unusual behaviors. For starters, you will notice that files seem to 'disappear'. Instead of a log file being modified under the common Program Files location, you may end up with multiple, and separate, copies for each user under "Compatibility / Program Files". Windows Vista/7 introduced file system virtualization, and will now create separate user instances of files to ensure to ensure that each user has their own secure copy.
Another problem you will encounter on Windows Vista, and to a lesser extent on Windows 7, is User Account Control (UAC) prompts. It's similar to the issue above, in that new security restrictions will now cause Windows Vista/7 to prompt the user for approval to proceed. The most noticeable area where this occurs is when you are tampering with executable files in sensitive directories, installing applications and drivers, and sometimes when trying to self-update an app (the abovementioned app actually works around these prompts with some smart logic).
So in short, security changes are the biggest difference between Windows XP and Windows Vista/7. Your best start is to separate application logic (binaries) from supporting logic, by putting the latter into user specific directories. Some apps may never be fixable and can be forced instead to work in Compatibility Mode or to launch always under the Admin account context --- poor workarounds, but may be suitable in your company.
Simon # http://AutoUpdatePlus.com
There are three parts to the migration. First, make it just plain work. This means fixing up hardcoded file paths (there's no more Documents and Settings), changing some of your save locations so you don't need to be elevated to work properly and don't rely on virtualization, changing some of your registry key locations for the same reason, and coping with high-DPI which might now be applied automatically based on screen size rather than as a user's choice.
Second, make it look and work like a Windows 7 application. Is your jumplist usable? Your thumbnail? You get some things for free, do you like what you get or would you like to take control? Are there obvious wins you could use like thumbnail buttons, jumplist tasks, taskbar overlays, etc. Don't surprise your users and don't disappoint your users. (Example of disappointment: VS 2008 and the crummy jumplists it offered. They had the excuse of being released before Windows 7 - you don't.)
Third, take advantage of Windows 7 to be greater than you otherwise would. Stop polling for network joins, file creation, hardware being plugged in, going on and off AC power etc and learn how to get notified when those things happen. Add touch support beyond what you get for free. Talk to a sensor or GPS for the first time, since Windows 7 makes it simpler than it ever was. That sort of thing.
1 is not optional. 2 is really not optional either, a year after Windows 7 is released. 3 will differentiate you and I recommend, once you get past 1 and 2, you look into it.
Basically Windows7 is a 4bit OS and so necessarily runs on a 64bit processor environment. XP has 32bit as well as 4 bit flavours. If your application is for the 32bit version of XP, in that case, the major migration means making the application run on 4bit OS effectively.
The basic steps can be something like this:
Make it compatible to 64bit win7. So you may just compile the code off a win7 machine (on 64bit). If the compilation works fine, you might be able to run the app successfully.
The first step just allows to move ahead. But your application might not be effective. In that case, you might have to review the code for any specific implementation coupled on 32bit os and upgrade them to take advantage of 64bit OS.
The major advantages on 64bit OS is higher address-ability (so access more RAM) and also cache etc.
I did some googling on differences between XP and Windows 7 but I do not get any proper links which describe how the internals of 7 differ from XP. Any links will be appreciated.
API diff report between XP and Vista: https://abi-laboratory.pro/compatibility/Windows_5.0_to_Windows_6.0/x86_64/abi_compat_report.html
API diff report between Vista and 7: https://abi-laboratory.pro/compatibility/Windows_6.0_to_Windows_7.0/x86_64/abi_compat_report.html
The reports are generated by the abi-compliance-checker tool.

Cross-debug Windows application on Linux box in Eclipse CDT

I'm moved from Windows to Ubuntu Linux, and now I want to set up development environment here. The problem is that I need
C/C++ IDE comparable to Visual Studio
Way to generate Windows PE binaries
Way do debug Windows PE binaries
At first time I tried Code::Blocks. Here I find guide to setting it up for cross-development so I managed to get "Hello World" compiled and running under Wine. Moreover, debugging worked too.
But then I found that Eclipse + CDT plugin is far more advanced IDE. I spent some time and finally get project compiled and linked.
Now I'm trying to get MinGW Insight version of GDB working within Eclipse CDT. Simple way to use debugger described in Code::Blocks guide won't work anymore. I continue to receive "Error creating session" messages.
So my question is, how I can use MinGW GDB under Wine as debugger back-end in Eclipse?
Or, what is best IDE for Linux->Windows cross-development?
I'm wondering that nobody answered this yet.
QtCreator. Don't be confused by its name, QtCreator works is pretty well with any kind of C++ code, you don't need to code in Qt to use it. It is just like FOSS Visual Studio: it does even have a syntax checking "on fly".
MinGW. Here's not much to say, it is just creates Win PE executables, and it works. It is available in repositories. Note, that a Win GUI applications have special bit in it's PE header set; so, in order to create GUI application with MinGW you have to pass an option -mwindows to set this bit.
This is a problem. Really: I'm just trying to debug a windows application, and didn't find yet a way to do it. I will shortly recall here what I tried so far, just in order for you to not step on my rakes:
winedbg. Probably it should work, but for me it didn't. When I set a breakpoint, i.e. like this br 43, it says Unable to add breakpoint (unknown address 7b860807).
winedbg. Yeah, again, but this time we will use it like this winedbg --gbd to make it proxying a commands to gdb. Probably this is the only way to debug an application, but it have a drawbacks: first, in order to restart an application you have to exit debugger; if you enter run it says that the remote target doesn't support this. Second, I have no even idea how to debug a multithreaded application; when I first started this, I stumbled upon an error Non-stop mode requested, but remote does not support non-stop, and after setting a breakpoint and starting it says:
Cannot insert breakpoint 1. and Cannot access memory at address 0x401654. So, in order to make this work I was needed to rename my .gdbinit file (i.e. non-stop mode is set there).
gdb.exe. I was sure that I found a way: simple usage of a windows version of gdb should solve problems; more over, for me, as I am a Emacs guy, it would be absolutely the same as debugging with native gdb. But alas, the windows gdb just didn't work. If I run it, and enter any command, it simply does nothing. It only reacts on Ctrl-c and Ctrl-z commands. Probably I will try on my spare time to ask a question about it on mailing list. Well, now we can't use it...
So what we have do with debug? Most probably seek another Windows debugger that works under WINE. If I correctly recall, OllyDbg worked, but I don't know at the moment how to make it show a source code.
you can try NetBeans.It's a good free, open source
and Cross Platform Support IDE.
Run Windows in a VM?
Seriously, your question is good, but it's probably not worth spending the time to figure out the answer (especially: since nobody seems to have a ready answer). If you have real work to do, native Windows or Windows in a VM is the answer.

Resources