I'm trying to pass the handle returned from u_fgetfile into fseek/fread functions.
When linking my application with the debug runtime libraries (/MTd /MDd) there is no crash, but if I link against the static versions this simple code crashes:
#include <stdio.h>
#include "unicode\ustdio.h"
int main()
{
UFILE* file;
file = u_fopen("C:\\test.txt","r",NULL,"UTF-8");
fseek(u_fgetfile(file),3,SEEK_SET);
}
Now this happens with both official builds of ICU and when I build custom builds with Visual Studio 2012 (building ICU in debug or release doesn't matter).
The only thing I have found out is that there seems to be some mismatch in the FILE structure, but I really don't know.
The problem is "icuio51.dll" (Release) is linked against the static CRT! Therefore it does not share the same FILE pointer with the shared CRT! And that´s the reason why it crashes in "lock"...
On the other hand: ´icuio51d.dll´ (Debug) is linked against the same shared CRT (msvcr110d.dll) and therefor are using the same shared FILE* pointer.
That´s the reason while it is working in "Debug" but not in "Release".
Solution: You have to recompile the ICU with the correct settings for always using "Shared CRT" (/MD and /MDd)... To do this, you have to make the follwoing steps: