Home › Forums › TWAIN Classic › Bad TWAIN structure definition
- This topic has 12 replies, 3 voices, and was last updated 15 years, 11 months ago by gabe.
- AuthorPosts
I was disappointed to discover that the SupportedGroups member of the TW_I_DEN_TI_TY(*) structure is NOT a TW_UINT32 type but TW_UINT16 instead (see: http://twain.org/devfiles/twain.h and the twain.h that comes with the developer toolkit, both are wrong).
Remember to update your copy of twain.h or you’ll lose time.
Alvise.
(*) sorry I had to add several underscore because the forum editor prevents me to type the exact word, but you understand what I mean
I just looked at the TW_IDENT ITY structure of several version of twain.h including the TWAIN Developers Toolkit, and all versions are correct and the same:
TW_UINT32 SupportedGroups;
Where is the version of twain.h that has SupportedGroups as TW_UINT16?
(*) The form editor does not like the word i d e n t i t
Very strange 🙁 ?I can’t answer to your question, I’ve corrected my header myself. The fact is the following: after a few hours of debug I noticed that the following strings:
TW_I_DEN_TI_TY.Manufacturer
TW_I_DEN_TI_TY.ProductFamily
TW_I_DEN_TI_TY.ProductNamewere shifted 2 bytes left. I.e: KODAK would have read DAK. And the SupportedGroups was an impossible number. As soon as I have modified the type of SupportedGroups from TW_UINT32 from TW_UINT16 all the strings got right (i.e.: KODAK was read KODAK) and the SupportedGroups was the true OR of DG_CONTROL and DG_IMAGE. Incredible, but true.
Now I am spending my time trying to set a TW_FIX32 capability (CAP_XRESOLUTION) using a TWON_ONEVALUE container. It looks like a “mission impossible”.
Any help about this ?
Alvise
Sounds like the structure packing is not set to 2
#pragma pack (2)
This is done automatically if you are including twain.h to get the structures. If you are defining your own structures then you will need to do this yourself.
Jim
Hi Jim, thanks for your interest. I am not defining my own structures, I have naturally included twain.h “as is”. I am using an old -but good- RAD, the Borland C++ Builder Pro release 3 (ehm, it dates back to 1997…) that I have installed in my Windows XP PC.
The pragma directive that you mention is obviously included in the header, but in the “#else” case of an “#ifdef __BORLANDC__” structure.
I am wondering whether I should reverse the cases in the ifdef structure, but I am not that expert to take such an initiative. At the same time I am wondering whether the absence of the #pragma pack (2) directive could be the cause of all the troubles that I am stumbling into (lots of TWCC_BADVALUE” when setting capabilities).
I need to get uncompressed B&W letter size images at 200 dpi from any TWAIN scanner, and I also am in a hurry. I am also considering to switch using the ISIS device driver, although this would mean restart programming from scratch.
Regards from Alvise.
Hi Jim, I’ve added the directive that you have suggested (#pragma pack (2)), but this did not solve the problems.
Regards. Alvise.
For those who are interested: into the TW_ID_ENT_ITY structure I’ve changed:
TW_UINT32 SupportedGroups;
into:
TW_UINT16 SupportedGroups;
TW_UINT16 dummy;and now everything works fine. The dummy word is set to zero.
Without the dummy word the following TW_STR32 strings would get shifted a couple of bytes right.
Alvise.
I still believe that the structure packing is not correct.
twain.h uses __BORLANDC__ to determine if you are using a Borland compiler. Make sure this is set in your environment. The switch for Borland is different than the one I gave earlier.
#ifdef __BORLANDC__
#pragma option -a2
#else
Jim Watters
Yes Jim, the pragma directive is exactly the one that you have typed. Afterall it comes with the original twain.h, and I have no reason to change it. And in fact I haven’t.
I confirm what you say, __BORLANDC__ is the compiler identifier, and for the Borland’s compiler the directive is #pragma -a2 and not #pack (2).
And looking into the data segment, the structures appear to be word aligned (every 2 bytes, even addresses, according to the #pragma -a2 directive). But the fact is that words in the data segment appear to be swapped.
Thanks for your interest. Alvise.
I agree with Jim. I’ve used SupportedGroups successfully with nothing more than an #import twain.h. The structure works… or more precisely – the structure works from vs6 and vs2005.
Again, not saying there is anything wrong with borland – just that you aren’t getting the same results I am from what sounds like the same code..
or to answer this in another way – when you run the toolkit sample – do you see the same problem with the structure?
.
Toolkit sample ? I didn’t notice it. Today I’ll re-inspect the package.
Thanks for the hint. Alvise.
this one:
http://twain.org/devfiles/twainkit.exe.
- AuthorPosts