.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I am using a dllimport from accore.dll, but the entry point for the method in the dll differs between 32-bit and 64-bit version of AutoCAD. How can I check whether the AutoCAD application is a 32- or 64-bit version, i.e. the dll is 32- or 64-bit?
Solved! Go to Solution.
Re: Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
public static bool IsX64()
{
if (IntPtr.Size == 4) return false;
else return true;
}
Sample of using: http://forums.autodesk.com/t5/NET/Can-t-find-Model
Other example: http://forums.autodesk.com/t5/NET/Save-a-password-
Re: Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Alexander,
public static bool IsX64()
{
return IntPtr.Size == 8;
}is less verbose and quite self explanatory.
Re: Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi
I didn't know about the IntPtr.size, so thank you for that information. But in my case I can't use this since I can't get IntPtr.size directly in a class where the dllimport is happening. You have to be whithin a method to use it.
Instead I used conditional compilation symbols and I compile one dll for 32-bit and one for 64-bit. By using the conditional compilation symbols the correct part of the code is compiled for each build.
Re: Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Fredrik.Larsen wrote:
But in my case I can't use this since I can't get IntPtr.size directly in a class where the dllimport is happening. You have to be whithin a method to use it.
Why? Did you watch the examples to which I referred?
Re: Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Yes, you're right. That might be easier leaving everything in one dll.
Re: Determine 32- or 64-bit applicatio n
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Sample that demonstrate common source code for different AutoCAD version and Platform (32 or 64 bit):
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
[assembly: CommandClass(typeof(Rivilis.HookESC))]
namespace Rivilis
{
public static class HookESC
{
static int AcadVer = AcAp.Application.Version.Major;
// For AutoCAD 2007 - 2012 64 bit
[DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRegisterFilterWinMsg@@YAHQ6AHPEAUtagMSG@@@Z@ Z")]
private static extern int acedRegisterFilterWinMsg2012x64(WindowHookProc callBackFunc);
[DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRemoveFilterWinMsg@@YAHQ6AHPEAUtagMSG@@@Z@Z" )]
private static extern int acedRemoveFilterWinMsg2012x64(WindowHookProc callBackFunc);
// For AutoCAD 2007 - 2012 32 bit
[DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRegisterFilterWinMsg@@YAHQ6AHPAUtagMSG@@@Z@Z ")]
private static extern int acedRegisterFilterWinMsg2012x32(WindowHookProc callBackFunc);
[DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRemoveFilterWinMsg@@YAHQ6AHPAUtagMSG@@@Z@Z") ]
private static extern int acedRemoveFilterWinMsg2012x32(WindowHookProc callBackFunc);
// For AutoCAD 2013 64 bit
[DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRegisterFilterWinMsg@@YAHQ6AHPEAUtagMSG@@@Z@ Z")]
private static extern int acedRegisterFilterWinMsg2013x64(WindowHookProc callBackFunc);
[DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRemoveFilterWinMsg@@YAHQ6AHPEAUtagMSG@@@Z@Z" )]
private static extern int acedRemoveFilterWinMsg2013x64(WindowHookProc callBackFunc);
// For AutoCAD 2013 32 bit
[DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRegisterFilterWinMsg@@YAHQ6AHPAUtagMSG@@@Z@Z ")]
private static extern int acedRegisterFilterWinMsg2013x32(WindowHookProc callBackFunc);
[DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRemoveFilterWinMsg@@YAHQ6AHPAUtagMSG@@@Z@Z") ]
private static extern int acedRemoveFilterWinMsg2013x32(WindowHookProc callBackFunc);
private static int acedRegisterFilterWinMsg(WindowHookProc callBackFunc)
{
if (AcadVer >= 19) {
if (IntPtr.Size == 4) return acedRegisterFilterWinMsg2013x32(callBackFunc);
else return acedRegisterFilterWinMsg2013x64(callBackFunc);
} else {
if (IntPtr.Size == 4) return acedRegisterFilterWinMsg2012x32(callBackFunc);
else return acedRegisterFilterWinMsg2012x64(callBackFunc);
}
}
private static int acedRemoveFilterWinMsg(WindowHookProc callBackFunc)
{
if (AcadVer >= 19) {
if (IntPtr.Size == 4) return acedRemoveFilterWinMsg2013x32(callBackFunc);
else return acedRemoveFilterWinMsg2013x64(callBackFunc);
}
else {
if (IntPtr.Size == 4) return acedRemoveFilterWinMsg2012x32(callBackFunc);
else return acedRemoveFilterWinMsg2012x64(callBackFunc);
}
}
// hook message filter callback function
[UnmanagedFunctionPointer(CallingConvention.Cdecl) ]
public delegate int WindowHookProc(ref Message msg);
private static WindowHookProc callBackFunc = null;
private static int WindowsHook(ref Message msg)
{
if (msg.Msg == 0x0100 && msg.WParam == (IntPtr)0x1b) {
// MessageBox.Show("ESC pressed"); // <- your's action
// acedRemoveFilterWinMsg(callBackFunc); // <- unregister callback
}
return 0;
}
[CommandMethod("SetHookEsc")]
public static void SetHookEsc()
{
callBackFunc = new WindowHookProc(WindowsHook);
acedRegisterFilterWinMsg(callBackFunc);
}
[CommandMethod("UnsetHookEsc")]
public static void UnsetHookEsc()
{
if (callBackFunc != null) acedRemoveFilterWinMsg(callBackFunc);
}
}
}




