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

Issues running .Net code that uses AcedGetSym in 32-Bit AutoCAD 2015

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
ainyoung
793 Views, 8 Replies

Issues running .Net code that uses AcedGetSym in 32-Bit AutoCAD 2015

Hello,

 

I have some .net code that needs to use AcedGetSym.

 

When the code is ran in AutoCAD 2015 32-bit, i get an error that AcedGetSym cannot be found in acCore.dll.

 

The same code runs fine in 32 bit verions of 2013 and 2014 and runs fine in 64-bit 2013-2015.

 

Has anyone else ran into this issue?

 

Thanks!

8 REPLIES 8
Message 2 of 9

AutoCAD 2015:

x86: "_acedGetSym" or "?acedGetSym@@YAHPB_WPAPAUresbuf@@@Z"

x64: "acedGetSym" or "?acedGetSym@@YAHPEB_WPEAPEAUresbuf@@@Z"

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 9

I'm using p/Invoke to use AcedGetSym.

 

    'Use P/Invoke for AcedGetSym
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

 

Message 4 of 9

For AutoCAD 2015 x86 (32-bit):

'Use P/Invoke for AcedGetSym
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="_acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

For AutoCAD 2015 x64 (64-bit):

'Use P/Invoke for AcedGetSym
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

 

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 9
ainyoung
in reply to: ainyoung

Here's an example code i wrote where a user can query if an AutoLISP symbol is valid.

I've tested the code in 64 bit versions of AutoCAD 2013 through 2015, and it works fine on those systems.

I've also tested the code on 32 bit versions of AutoCAD 2013 through 2015. It only fails to run on 32 bit 2015.

AGS_Class.vb

 

'import the AutoCAD/ObjectDBX type libeary

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput

Imports System.Text ' for StringBuilder
Imports Autodesk.AutoCAD.DatabaseServices ' For ResultsBuffer

Imports System.Runtime.InteropServices 'for DllImport()
'imports the AutoCAD Type library
Imports Autodesk.AutoCAD.Interop

Imports Autodesk.AutoCAD.ApplicationServices
Imports System.Windows.Forms

Public Class AGS_Class

    'Define ThisDrawing. The production code i am working on was converted from VBA to VB.NET, hence this has to be defined. 
    Public ReadOnly Property ThisDrawing() As AcadDocument
        Get
            Return DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument)
        End Get
    End Property

    'Define the entry point/command. 
    <Autodesk.AutoCAD.Runtime.CommandMethod("AIY_AcedGetSym_Test")> _
    Public Sub EntryPoint()
        Dim My_Form1 As New Form1
        My_Form1.ShowDialog()
    End Sub

    'Use P/Invoke for AcedGetSym
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

    Public Shared Function AcadGetSym(ByVal varname As String) As ResultBuffer
        ' IntPtr is an integer (used as a pointer for .NET) initialize to zero
        Dim rb As IntPtr = IntPtr.Zero
        ' use the function that was p/Invoked, pass in the name that was 
        ' provided by the user and the IntPtr
        Dim stat As Integer = 0
        stat = acedGetSym(varname, rb)
        ' If stat is ok and the IntPtr is not zero create a ResultBuffer and Return it
        If stat = CType(PromptStatus.OK, Integer) AndAlso Not (rb = IntPtr.Zero) Then
            Return CType(DisposableWrapper.Create(GetType(ResultBuffer), rb, True), ResultBuffer)
        End If

        ' Getting the symbol failed if we reach this return statement
        Return Nothing
    End Function

    Public Shared Function GetLispStrSym(ByVal sym As String) As String
        ' Get the string value of a Lisp symbol
        ' The name (or expression) of the lisp symbol is passed in sym.
        ' Adapted from CP 214-4 AutoCAD® .NET: Using .NET With Your LISP Applications example
        '   Output values are returned in an AutoCAD specific ResultBuffer.
        '   ResultBuffer can contain int, float, string, etc. 
        '   This routine only accomodates a string!

        ' Populate a ResultBuffer with the values of the symbol by calling
        ' local function AcadGetSym which uses acedGetSym that was called through
        ' P/Invoke

        Dim ResBuf As ResultBuffer = AcadGetSym(sym)

        ' Ensure that ResultBuffer is not nothing
        If Not (ResBuf Is Nothing) Then
            Dim s As StringBuilder = New StringBuilder
            ' Append each type and value in the symbol
            For Each val As TypedValue In CType(ResBuf, IEnumerable)
                If val.TypeCode = 5005 Then 'is it a string?
                    s.AppendFormat("{0}", val.Value.ToString)
                Else
                    GetLispStrSym = "Valid LISP symbol, but it's not a string!"
                    Exit Function
                End If
            Next
            GetLispStrSym = s.ToString()
        Else
            GetLispStrSym = "*That's not a Lisp Symbol*"
        End If
    End Function


End Class

 The simple form code:

Public Class Form1

    'setup an example LISP symbol input. 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        EnterText.Text = "pi"
    End Sub

    'On cliking okay, we pass the entered entered text into GetLispStrSym
    Private Sub Okay_Click(sender As Object, e As EventArgs) Handles Okay.Click
        ReturnTxt.Text = AGS_Class.GetLispStrSym(EnterText.Text).ToString
    End Sub
    'Exit if canceled. 
    Private Sub CanIt_Click(sender As Object, e As EventArgs) Handles CanIt.Click
        Me.Close()
    End Sub


End Class

 

 

Message 6 of 9

Reread my answer.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 9

I'll give that a try once my 32 bit test VM isn't in use.

 

Is there any alternative call that works for both 32 bit and 64 bit so i don't have to add a complication constant to do a condiontal compilation?

 

Right now the same code base is used to build all versions, 2012 to 2015 32 and 64 bit, of a given project.

 

 

Message 8 of 9

You can check AutoCAD version and platform (32bit/64-bit) at runtime and call appropriate function. Also you can use conditional compilation.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 9 of 9

I finally got a chance to test this out on my 32 bit VM and it works fine!

 

Thanks for the help!!

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