Libtiff's TIFFOpenW throws exception

733 views Asked by At

I'm using LibTiff v4.0.3.

I had it working perfectly in multibyte, but when i try to work with Unicode, I get a runtime exception.

I can render the problem down to a single line:

#include "tiffio.h"

int _tmain(int argc, _TCHAR* argv[])

{  
    TIFF* tif = TIFFOpenW(L"D:\\Myfile", "r");
}

And this will work perfectly: TIFF* tif = TIFFOpen("D:\\Myfile", "r");

I can't get the exact exception code, but the code stack looks like this:

msvcr110.dll!__crt_debugger_hook(int _Reserved) Line 60 C
msvcr110.dll!_call_reportfault(int nDbgHookCode, unsigned long dwExceptionCode, unsigned long dwExceptionFlags) Line 155    C++
msvcr110.dll!_invoke_watson(const wchar_t * pszExpression, const wchar_t * pszFunction, const wchar_t * pszFile, unsigned int nLine, unsigned __int64 pReserved) Line 139   C++
msvcr110.dll!_invalid_parameter(const wchar_t * pszExpression, const wchar_t * pszFunction, const wchar_t * pszFile, unsigned int nLine, unsigned __int64 pReserved) Line 85    C++
msvcr110.dll!_invalid_parameter_noinfo() Line 97    C++
msvcr110.dll!_read(int fh, void * buf, unsigned int cnt) Line 84    C
ConsoleApplication1.exe!TIFFFdOpen()    C
ConsoleApplication1.exe!TIFFClientOpen()    C
ConsoleApplication1.exe!TIFFFdOpen()    C
ConsoleApplication1.exe!TIFFOpenW() C
ConsoleApplication1.exe!wmain(int argc, wchar_t * * argv) Line 21   C++
ConsoleApplication1.exe!__tmainCRTStartup() Line 533    C
ConsoleApplication1.exe!wmainCRTStartup() Line 377  C
kernel32.dll!BaseThreadInitThunk()  Unknown
ntdll.dll!RtlUserThreadStart()  Unknown

I've tried using @err and @err,hr , but they show that there was no error.

How can I get the Unicode version to work ? Do I need to compile the library differently?
(I've checked and there's no check for the preprocessor variable UNICODE in libtiff....)

1

There are 1 answers

0
Yochai Timmer On BEST ANSWER

Turns out you need to compile the library a bit differently when linking to debug mode project in Unicode.

Go to your libtiff folder, and open nmake.opt for editing.
Change the compilation flags to use debug CRT dlls (/MDd):

OPTFLAGS =  /Ox /MDd /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE

instead of just /MD

Now rebuild the library.

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\vcvars32.bat"  x86
nmake /f makefile.vc   [clean]

or for x64:

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64\vcvars64.bat"  amd64
  nmake /f makefile.vc   [clean]

Make sure your project links to that file when you're in the debug configuration