I wrote a vb .net script to extend the TCL interpreter for postbuilder.
The program works well on NX7.5 but the same program does not work on NX9.0.
Here is the code, uggsFn is the entry point:
Private Shared Ufs As UFSession = UFSession.GetUFSession() Private Shared theSession As Session = Session.GetSession() Public Shared Function uggsFn(param As String) As Integer MsgBox("Hello") Dim mom_id As IntPtr = IntPtr.Zero Ufs.Mom.AskMom(param, mom_id) Return 0 End Function
The code is extremely simple. MessageBox is shown in NX when the dll is used by the post builder. But
gives me error in NX9 but works find in NX7.5.
The exception thrown reads as following:
Caught exception while running: uggsFn System.InvalidCastException: Conversion from string "?/r??" to type 'Long' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDecimal(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToLong(String Value)
Any idea why this is happening?
I am running Windows 10 and I tried the program on windows 7 64-bit too. Same result.
Thanks in advance
Solved! Go to Solution.
This has changed to the following:
Dim MOM_ID As IntPtr = IntPtr.Zero theUFSession.Mom.AskMom(Runtime.InteropServices.Marshal.StringToHGlobalAuto(Args(0)), MOM_ID)
Development: VB.NET, Tcl/Tk Testing: NX12.0 Preparing: NX12.0
Employees of the customers, together we are strong
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide
Thank you for your reply. To be clear, do you mean I need to write my function like this?
Public Shared Function uggsFn(Args() As String) As Integer MsgBox("Hello") Dim mom_id As IntPtr = IntPtr.Zero Dim paramPt As IntPtr = CType(param, IntPtr) Ufs.Mom.AskMom(Runtime.InteropServices.Marshal.StringToHGlobalAuto(Args(0)), mom_id) Return 0 End Function