An error occurred while migrating the 32-bit compiled vsto plug-in to the 64-bit Office product. A thread Hook was used in vsto to respond to mouse and keyboard events.

Source: Internet
Author: User

Some time ago, I published an article titled using thread hooks in vsto to respond to mouse and keyboard events. At that time, the compiling environment was 32 bits, and later in the 64-bit office, I thought it would run smoothly in wow64, but unfortunately, after the document is started, an exception will be thrown if there is a mouse or Keyboard Message. As follows:

As you can imagine, most of them are caused by inappropriate data types, So I adjusted the code and found such a description on msdn, which caused my attention: 64-bit applications

 

When assemblies run identically on both the 32-bit Clr and the 64-bit CLR. However, some programs may behave differently, depending on the CLR, for one or more of the following reasons:

  • Structs that contain members that change size depending on the platform, for example, any pointer type.

  • Pointer arithmetic that has des constant sizes.

  • Incorrect platform invoke or com declarations that useInt32For handles insteadIntptr.

  • CastingIntptrToInt32.

At first, I didn't understand why I pointed out intptr separately. I checked the description of intptr type to understand that the size of the original intptr address varies with the operating system, that is, in a 64-bit operating system, a 64-bit office is directed to int64 rather than int32. Therefore, in my previous code, all statements that involve intptr to int are described as follows, an Arithmetic overflow exception occurs. After understanding this, the changes made are clear. To ensure that all intptr files are executed on the 32/64-bit platform at the same time, replace all intptr files with int values. If you want to treat them differently, intptr and int32 or int64 should be converted explicitly. The goal is to use the same data type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.