Another interesting issue today with an application that runs on Citrix XenApp.

Customer has a Citrix XenApp 5 environment running on Windows Server 2003. Clients are all Windows XP and run the Citrix Online Plugin 12.3 full screen.

RES Workspace Extender is used to integrate locally installed application into the XenApp Session. Users have no access to the local desktop.

This particular application scans invoices using a USB scanner attached to the client and runs them trough a workflow.
Whenever the Start scan button was pressed the application froze.



Since the application was no longer responding I could only kill the process. However when I did this, the whole session freezed.

The only thing I could do was reset the whole session via the management console.

In order to fix this problem we need to understand how twain redirection is implemented in XenApp.

Twain Redirection
When an application running in a XenApp session calls into the Twain API’s in order to obtain an image from a scanner the call is intercepted by a hook dll called twnhook.dll.

So my first step was to verify that twnhook.dll was correctly configured in the registry:


Then I verified that the hook dll was loaded into the target process with Process Explorer (enable the Lower Pane View and set it to DLL’s):


On the client side a process called CtxTwnPA.exe is launched, this executable calls the TWAIN driver and communicates with the XenApp server through a Virtual Channel.

I verified CtxTwnPA.exe was being launched and that this process had loaded the twain dll:


I right-clicked the CtxTwnPA.exe process in Process Explorer and selected Window | Bring To Front and that showed this Window:


I am not sure why this window is appearing since there is only one scanner to select but clearly the application was not hanging but was waiting for this dialog to be closed!

In theory this shouldn’t be a problem since the RES Workspace Extender should display this window in the XenApp session but it doesn’t. This happens because the dialog window doesn’t have an associated icon in the taskbar.

This is by design when using the Workspace Extender (RES Virtual Desktop Extender (VDX) doesn’t have this limitation).

I figured that if I could force this dialog to have a taskbar icon it would solve my problem.

I am not going to explain in detail here how resources in c/c++ applications work, but in a nutshell a dialog is composed as a resource script that can be modified with tools such as Resource Hacker.

I loaded twain_32.dll into Resource Hacker and found the dialog:


In order for an application to have an icon on the taskbar we must make sure that the Window Style contains the WS_POPUP attribute and that the Extended Window Style contains the WS_EX_APPWINDOW attribute.

So I modified the resource script from:


Then I recompiled the script with the Compile Script button and saved the Executable.

Now the Select Source Dialog has a Taskbar Icon and is displayed correctly in the session by the RES Workspace Extender:


When replacing twain_32.dll on Windows XP please note that the file is protected by Windows File Protection. You can use my WfpReplace tool to easily overwrite it!