Notifications
Clear all

[Closed] How to call ILogSys.LogEntry() in Max.NET

Hello,

I am writing a plugin using the managed wrapper provided by Autodesk (Max 2014) for the Max SDK.

I would like to write to the Max log file, which I believe I do through the LogSys object, however something goes wrong whenever I try to do so.

I get an instance of ILogSys from the global interface and call LogEntry() on it like so:

 logger.LogEntry(SYSLOG_INFO, false, "MyPlugin", "%s
", message);

Where message is a regular string, with nothing fancy in it.

In the Max.Log file however I get:

2013/12/29 20:53:11 INF: [125716] [125720] [I]bs[/I]

Where bs is the ‘backspace’ character according to Notepad++.

Is there anything special I have to do when using this method in the wrapper? Specify how the strings should be marshaled explicitly? Convert them?

2 Replies
Where message is a regular string, with nothing fancy in it.

what type is it exactly ?

if its a “regular” c# string class then try

 message.ToCharArray();

or Max CStr try

 message.data();

or is it ?

char[] message;

EDIT

OK I fixed it/came up with a workaround:

logger.LogEntry(SYSLOG_INFO, false, "DazMaxBridge", message + "
");

Or if you like

logger.LogEntry(SYSLOG_INFO, false, "DazMaxBridge", string.Format("{0}
",message));

(It took far too long for me to think to do that. I know the expression “woods for the trees” but this is being unable to see the garden for the sickly Dwarf Willow tree in the corner…)

Hi Klunk,

It is a regular C# string. I tried ToCharArray() and the character became a question mark, so I then tried Encoding.ASCII.GetBytes(message) and the character became a dash (-)!

In the Max SDK documentation they use this _M() macro, does this create a Max CStr you mentioned? I wonder if I need to convert to this.

It occurred to me that whether I add a null terminator or not, that the log always displays a single character (and it changes depending on what type of object I pass), so maybe its reading the reference as the data.

I tried to fix the string in memory and send a pointer directly with

fixed (char* msgPtr = message.ToCharArray())

But the method will not accept a char* in place of an object.

I then tried to use

Marshal.StringToHGlobalAuto(message)

and pass an IntPtr but this has the same issue as passing any other managed object.