It's actually the old post of a previous blog. If you haven't written a blog for too long, paste it.
Since max9, maxscript can directly call. Net DLL files and create classes to use the methods. And. Net can call the DLL file written in C ++. Therefore, you can use C # to encapsulate the C ++ code and call it in Max. The following is an example.
--------------- Below is DLL. Def
Library "DLL"
Exports
Helloworld @ 1
-------------- The following is the DLL. cpp File Content
Bool apientry dllmain (handle hmodule,
DWORD ul_reason_for_call,
Lpvoid lpreserved
)
{
Return true;
}
Void helloworld (
{
MessageBox (null, l "C ++ DLL", text ("in Win32 DLL"), mb_ OK );
}
------- The following is an encapsulation file of C # And compiled as importdll. dll.
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. runtime. interopservices;
Namespace importdll
{
Public class win32dll
{
[Dllimport ("DLL. dll", entrypoint = "#1")]
Public static unsafe extern void helloworld ();
}
}
------------- Can then be called in maxscript
DOTNET. loadassembly (getfilenamepath (getsourcefilename () + "importdll. dll ")
(Dotnetclass "importdll. win32dll"). helloworld ()
------------------------
Here I used the serial number export method. If you do not want to use the def file to export the serial number, you can use the extern "c" to export the method in C language, this is because the exported Method Name of C ++ does not match the name in the DLL source file.
The only benefit of using. net instead of using maxsdk is that it does not have to be subject to version restrictions and does not need to be compiled for different versions. Of course, this method is only limited to extensions without any operation on Max. If the operation on Max is involved, you can only honestly use the SDK.