Notifications
Clear all

[Closed] SDK Maxscript Extention help

Good to know.

Re: the _s version of strcpy, well, essentially MS designed a ‘safe’, though non-standard, version of almost every std C library function, and by default issues deprecation/security warnings when you try to use them.

Since this code is out of your control, (it’s in standard max headers), there’s not much you can do except disable those warnings by #define’ing _CRT_SECURE_NO_WARNINGS, as the warning states.

Most of the std C functions are relatively safe, provided you’re careful about how you use them. Some are rather unsafe and should be avoided (gets, sprintf), as they don’t let you specify buffer lengths, etc. I personally don’t use these _s functions myself. The Win32 API provides a lot of safe C string manipulation functions to use too. (Most, if not all, of the C runtime is implemented in terms of the win32 api anyway, the C API is pretty much just an abstraction (albeit standard, that can be compiled almost anywhere) above pure Win32 platform code.)

Anyhow, enough rambling on the C library, you can either ignore the warnings, but I recommend you define that macro to suppress them, as they are out of your control, and not too serious.

I suggest you do it as part of your project instead of polluting your source code, by adding it to C+±>Preprocessor->Prepoc. Definitions. This basically adds the symbols to the command line via the /D switch.

cool thanks

I have a stupid question. Can we use “strcpy_s” or any of the other “_s” functions with in own code for the plugins?

Personally, I wasn’t really going to, been new to the plugin scene and having to re-learn c++, but I thought I might seek some clarification for the future.

(Max 8/9 and VS 2005)

Cheers
Shane

Of course you can. They are essentially a vendor-specific extension to the CRT, to provide an extra level of safety.

I personally just avoid them and use Win32 API directly, since I’m not actually gaining anything by using non-standard C functions, as no one but MS implements them anyway (they did propose them to the ISO however), and I’m just needlessly going through an extra level of abstraction, and incurring an extra dependency on the CRT.

If you look up strcpy on MSDN, you will (rightfully) get a security warning on buffer overruns, with some recommendations of alternative functions. While strcpy_s is fine, you may as well dive down and use the native code equivalent, StringCbCopy(), as a) strcpy_s is probably implemented in terms of the native platform API anyway, so really you are in effect calling it indirectly, and more importantly b) StringCbCopy() works on generic strings TSTR’s, whereas strcpy_s works on ANSI strings, and wcscpy_s is the used for Wide strings, etc.

Of course you’d be better off using _tcscpy_s() as the generic version of the strcpy_s family if you were set on using the CRT (extension).

ok i’m going slightly off topic now…

I’m trying to call a function in a C# DLL from my maxscript extention. At the moment i’m still working in the intervalarray project as a base just because i know its already working. The problem seems to be that i need to use /clr however when I do, even if I dont change any of the code, i get 19 warnings and 109 linker errors !!!

i just tried to attach the build transcript but it is 31k and the attachment thingy said that the max for txt files is 19k… go figure… so anyway, i’ve copy/pasted a few of the errors since they are mostly the same
ie. warnings C4793, C4747, errors LNK2028, LNK2020, LNK2001, LNK2019, LNK1120

error LNK2020: unresolved token (0A000F92) "public: __thiscall CStr::~CStr(void)" (??1CStr@@$FQAE@XZ)	intervalarray.obj

error LNK2028: unresolved token (0A000E7E) "int __cdecl assert1(int,char *)" (?assert1@@$FYAHHPAD@Z) referenced in function "public: class BaseInterface * & __thiscall Tab<class BaseInterface *>::operator[](int)const " (??A?$Tab@PAVBaseInterface@@@@$FQBEAAPAVBaseInterface@@H@Z)	dllmain.obj

error LNK2019: unresolved external symbol "public: void __thiscall Matrix3::IdentityMatrix(void)" (?IdentityMatrix@Matrix3@@$FQAEXXZ) referenced in function "public: virtual void __thiscall DelayedMatrix3::InitializeMat(void)" (?InitializeMat@DelayedMatrix3@@$FUAEXXZ)	dllmain.obj

error LNK2001: unresolved external symbol "public: void __thiscall Matrix3::IdentityMatrix(void)" (?IdentityMatrix@Matrix3@@$FQAEXXZ)	intervalarray.obj

warning C4793: 'vararg' : causes native code generation for function 'int CharStream::printf(const TCHAR *,...)'	c:\program files\autodesk\3dsmax8\maxsdk\include\maxscrpt\Streams.h	37

warning C4747: Calling managed '_DllMain@12': Managed code may not be run under loader lock, including the DLL entrypoint and calls reached from the DLL entrypoint	d:\Visual Studio Projects\intarr\intarr\dllmain.cpp	1

If anyone can shed any light on if using /clr in a maxscript extention is even possible and if so, how, that would be great.

Yes, you can use managed code in a MAXScript extension plugin. The dotNet bridge is compiled with /clr parameter. The sample is located at maxsdk\samples\maxscript\mxsdotNet.

If you examine the code (not easy to read and understand, C++/CLI is just usefull to write glue code) you can find #pragma managed and #pragma unmanaged. Put #pragma managed before writting managed classes and write #pragma unmanaged before Max / unmanaged code. Also, each C++ source file can be marked as using or not /clr (right-click and see file properties).

Here is what I know about mixing unmanaged and managed code with C++/CLI.
C++/CLI master article page: http://www.voidnish.com/Articles.aspx
Here is another interesting C++/CLI resource: http://www.functionx.com/vccli/index.htm

Thanks again but i’m still having trouble… I can’t find the sample you mensioned at maxsdk\samples\maxscript\mxsdotNet. We’re still using max 8 at work so i’m guessing it was added in max 9? If that is the case, would you mind posting the sample for me please.

Page 3 / 3