FAQ (Frequently Asked Questions)
for .NET developers on using WSQ image library





In "MS Visual Studio 2010" and .NET 4.0 Framework my application crashes when making call to "WSQ image library" DLL. What should I do?

Important notes for using "WSQ image library" in "MS Visual Studio 2010".

1. "WSQ image library" is a native 32-bit Windows DLL.

In IDE of MS "Visual Studio 2010" you need to set "targeted platform" as "x86".

2. You need to "run as administrator" the IDE compiler and application.

3. .NET 2.0+ assumes that DLL calling convention is Cdecl, while .NET 4.0 does not.

You need to explicitly set calling convention to Cdecl when using "WSQ image library" in .NET 4.0.

As for example:

Visual C# .NET

NET 2.0+ version:

  
[DllImport("WSQ_library.dll")]
public static extern int _RegisterWSQ();

NET 4.0 version:

  
[DllImport("WSQ_library.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern int _RegisterWSQ();

Visual Basic .NET

NET 4.0 version:

  
<DllImport("WSQ_library.dll", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Auto)> _
Shared Function _RegisterWSQ() As Integer
End Function

4. When trying to run application in "MS Visual Studio 2010" you might receive the error message
"Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang".

The solution:

In IDE go to the menu "Debug", then go to the menu "Exceptions", and then expand "Managed Debugging Assistants", and uncheck "Thrown" for "LoaderLock".

5. If application is built targeting version 4.0 of the .NET Framework, the call to the unmanaged DLL will always fail with a StackOverflowException under the debugger.

If application is built targeting version 3.5 (or lower) of the .NET Framework, it works correctly.

The solution:

As a workaround solution is to run the application in IDE without debugger (Ctrl-F5), then application will work correctly. Also you can build application and run it outside of IDE.

This is a known bug of "MS VS2010 compiler". Please check out for updates and hotfixes from Microsoft for the latest solution to this problem.






I am using ASP.NET on Windows 2003 Server and IIS 6.0. I am writing web application which loads WSQ image library DLL, however my application fails to load DLL.

The problem is caused by IIS 6.0.

IIS 6.0 does not support full set of Win32 API functions, including very fundamental ones like for example MessageBox or creating and showing Forms.

The only solution to this problem is to remove from DLL all native Win32 API calls which IIS 6.0 fails to support and recompile DLL with all MessageBoxes and Forms removed. Cognaxon has built such ripped version of DLL which IIS 6.0 is able to load.

To download special version of "WSQ image library" with Registration utility click here

To download Microsoft Visual C# .NET 2003 sample project click here

To download Microsoft Visual Basic .NET 2003 sample project click here

Please extract the zip file, inside you will find file “WSQ_library.dll” which is a version of DLL build specially to work under ASP.NET + II6.0 environment.

This version of “WSQ image library” DLL is almost identical to standard version of DLL, only with small difference:
it does not have pop-up window of "file properties"

and it does not have "file format converter" utility

but most probably you do not need them anyway (in other words in this version of DLL all Forms and MessageBoxes are removed).

Also please note that ASP.NET requires that DLL files must be located in "system32" directory/folder. As for example, under Windows XP you need to copy the file "WSQ_library.dll" to "C:\WINDOWS\system32" directory/folder.




My application calls the function from WSQ image library DLL. The function returns correct value, however in the next line of .NET program code my application crashes. What should I do?

This problem affects all Win32 DLLs which are called from .NET program. And WSQ image library is exactly Win32 DLL, so it is affected too.

It is known bug of .NET platform.

This issue is caused by thirty-part applications or controls (in our case by "WSQ image library" DLL), which change floating-point control register so floating-point exceptions like overflow are unmasked.

.NET Framework assumes that the FPU control register is set to mask floating point exceptions.

The solution is to declare function in your code

Visual Basic .NET

  
<DllImport("msvcr70.dll", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Auto)> _
Shared Function _controlfp(ByVal n As Integer, ByVal mask As Integer) As Integer
End Function

Visual C# .NET

  
[DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int _controlfp(int n, int mask);


And after calling any function from Win32 DLL you need to reset the FPC Register (Word) to its default value as expected by .NET framework.

Program code for reseting FPC Register is

Visual Basic .NET

  
_controlfp(&H9001F, &HFFFFF)

Visual C# .NET

  
_controlfp(0x9001f, 0xfffff);



As a demonstration of this problem consider Visual Basic .NET code

  
OutputPicture.Image = Bitmap.FromHbitmap(_CreateBMPFromFile(lpszDialogFileName))          
'After calling function in Win32 DLL you need to reset the FPC Register (Word)
'to its default value as expected by .NET framework
_controlfp(&H9001F, &HFFFFF)
Dim Font1 As Font
Font1 = New System.Drawing.Font("Courier New", 8.25F, _
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)



If you remove line

  
_controlfp(&H9001F, &HFFFFF)

from the code, the application will crash trying to create font on line

  
Font1 = New System.Drawing.Font("Courier New", 8.25F, _
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)








Copyright © 2019 Cognaxon. All rights reserved. Privacy