TheSwamp
Code Red => .NET => Topic started by: Bobby C. Jones on August 29, 2006, 04:11:55 PM
-
Acad 2005
Can anyone see what I'm doing wrong? The call to acedSetVar is returning -5001, and the MODEMACRO value doesn't change. Thanks.
[DllImport("acad.exe", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Auto)]
public static extern int acedSetVar(string variableName, IntPtr value);
public static void SetModeMacro(string value)
{
ResultBuffer val = new ResultBuffer(new TypedValue((short)DxfCode.Text, value));
int retval = acedSetVar("MODEMACRO", val.UnmanagedObject);
Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message(retval.ToString());
}
-
I've noticed with some imports that they require the mangled name of the exported arx function, maybe this is the case here??
-
The compiler mangled name in 2006:
?acedSetVarFromBag@@YAHPBDPBUresbuf@@@Z
Dumpbin that ships with Visual studio will do this. Fire a Visual studio command prompt and change to acad folder.
Then type in: Dumpbin /EXPORTS "YourpathToAcad.exeHere" >> "C:\Temp\AcadExports.txt". Once you have the exported exports :D
just search the file for what you need.
Hope this helps.
Cheers,
Glenn.
-
<deleted>
Glenn beat me to it .. :lol:
-
I've been playing with some late binding, Interop and Reflection.
This will work. (You don't need an Interop reference to Autocad since late binding is used:
public static void SetModeMacro(string value)
{
object[] parameters;
object acadapp = null;
object cmd = null;
object dwg = null;
acadapp = (object)Marshal.GetActiveObject("AutoCAD.Application");
dwg = acadapp.GetType().InvokeMember("ActiveDocument",
BindingFlags.GetProperty, null, acadapp, null);
string sTemp = "(Command " + @"""" + "MODEMACRO" + @"""" + " " + @"""" +
value + @"""" + " )" + "\r";
parameters = new object[1];
parameters[0] = sTemp;
cmd = dwg.GetType().InvokeMember("SendCommand",
BindingFlags.InvokeMethod, null, dwg, parameters);
}
I'd be interested in opinions as to which method to use.
-
I see both exports, but both give the same result :-(
[DllImport("acad.exe", EntryPoint = "?acedSetVarFromBag@@YAHPBDPBUresbuf@@@Z", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
public static extern int acedSetVar(string variableName, IntPtr value);
Any other ideas? Thanks.
-
Any other ideas? Thanks.
[CommandMethod("TEST")]
static public void test()
{
SetModeMacro("12345");
}
// From adscodes.h :
const int RTSTR = 5005; /* String */
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern int acedSetVar(string variableName, IntPtr value);
public static void SetModeMacro(string value)
{
ResultBuffer val = new ResultBuffer(new TypedValue(RTSTR, value));
int retval = acedSetVar("MODEMACRO", val.UnmanagedObject);
Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message(retval.ToString());
}
I think you can find yourself errors in yours code... :-)
-
I think you can find yourself errors in yours code... :-)
CharSet.Ansi
const short RTSTR = 5005;
That did it. Thank you Alexander.
-
:-)