Hello Mark,
From your post, my understanding on this issue is: (1) how to make a COM
client works well in both 32bit and 64bit environment and (2) how is IntPtr
translated to unmanaged environment. If I'm off base, please feel free to
let me know.
(1) how to make a COM client works well in both 32bit and 64bit environment
I find a good article that talks about "Accessing 32-bit Dlls from 64-bit
code"
http://dnjonline.com/article.aspx?ID=jun07_access3264. As the article
says, 64bit code and 32bit code cannot co-exist in one process. I
reproduced it when I registered a COM object written in C# with 64bit
regasm.exe, and use a 32bit C++ client application to create the COM
object. The 32bit application is not able to create the object and throws
an exception.
The possible workarounds are:
1. As the article
http://dnjonline.com/article.aspx?ID=jun07_access3264 says, we could use DCOM, an out-of-process COM component. DCOM is still
supported on 64-bit Windows platforms, so both 32-bit and 64-bit COM
modules can be built. The only limitation is that 64-bit and 32-bit modules
cannot reside in the same process space, so they have to interoperate
across process boundaries.
2. As you said, building 2 versions of the COM DLL may not be a good
resolution, but it can help to resolve the problem indeed. The 32bit
version of COM object is for 32bit clients, and the 64bit version is for
64bit applications.
(2) how is IntPtr translated to unmanaged environment
According to the MSDN article
http://msdn2.microsoft.com/en-us/library/system.intptr(VS.71).aspx, The
IntPtr type is designed to be an integer whose size is platform-specific.
That is, an instance of this type is expected to be 32-bits on 32-bit
hardware and operating systems, and 64-bits on 64-bit hardware and
operating systems. It is translated to "long" in my test C++ client
application and it works well both in both 32bit system and 64bit one.
Please let me know if you have any other concerns, or need anything else.
Sincerely,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document:
http://blogs.msdn.com/msdnts/pages/postingAlias.aspx Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.