When I build my application in 32 bit windows, I got this error in 64 bit windows
System.MissingMethodException: Method not found: 'Int32 Autodesk.AutoCAD.Interop.IAcadApplication.get_HWND
And when I build it in 64 bit windows, I got
System.MissingMethodException: Method not found: 'Int64 Autodesk.AutoCAD.Interop.IAcadApplication.get_HWND
What can I do?
I think it is due to the getting hwnd of autocad. I am using this hwnd to show the userforms owner.
If anybody has a different suggestion, I can change my code.
AcadHwnd = Acad.HWND . . . owner = New WindowWrapper(CType(AcadHwnd, IntPtr)) . . . Dim form1 As New Form1 form1.Show(owner)
Not sure about your use case, but the standar way to show a modal dialog in AutoCAD is via Application.ShowModalDialog(DialogInstance).
As I understood, the HWND property in IAcadApplication is declared as int in 32-bit AutoCAD installation. In 64-bit AutoCAD installation, however, it's declared as LONG_PTR. So when you compile your project in 32-bit platform, the compiler uses int, and when you compile in 64-bit, is uses LONG_PTR.
It is possible, however, to use .NET InvokeMember() function. I DO NOT KNOW whether it is safe or not; but it works for me.
acadApp.GetType().InvokeMember("HWND", System.Reflection.BindingFlags.GetProperty, null, acadApp, null)
Use HWND in program:
BringWindowToTop((IntPtr)System.Convert.ToInt64( acadApp.GetType().InvokeMember("HWND", System.Reflection.BindingFlags.GetProperty, null, acadApp, null)));
In the second example, we use System.Convert.ToInt64() at first (to ensure we can use the 64-bit AutoCAD return value), and then convert the result to IntPtr (handle type).
I don't know whether it is good or bad; I just hope it is correct.)
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register