.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determine 32- or 64-bit application

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Fredrik.Larsen
4166 Views, 7 Replies

Determine 32- or 64-bit application

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?

7 REPLIES 7
Message 2 of 8

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-ModelessOperationWill-Start-Event-in-Dot-net/m-p/344769...

Other example: http://forums.autodesk.com/t5/NET/Save-a-password-protected-drawing-without-password-with-VB-NET/m-p...

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 8
_gile
in reply to: Alexander.Rivilis

Hi Alexander,

 

public static bool IsX64()
{
   return IntPtr.Size == 8;
}

is less verbose and quite self explanatory.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 8
Alexander.Rivilis
in reply to: _gile


@_gile wrote:
is less verbose and quite self explanatory.

Totally agree!

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 8

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. 

Message 6 of 8


@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?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 7 of 8

Yes, you're right. That might be easier leaving everything in one dll. 

Message 8 of 8

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);
    }
  }
}

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost