Notifications
Clear all

[Closed] C++ Plugin conversion from 2012 to 2013

Hello guys,
I have a serious C++ SDK problem and I think it is beyond my skills…

I have an exporter plugin from 3dsmax to another software (Virtools for the ones knowing it).

At one side, I have the Virtools SDK to export in the proprietary format expected by Virtools. It includes the methods to create meshes, textures, materials, etc… in Virtools own format. So I have to use this SDK.
This SDK is made for VS2008 and does not handle UNICODE strings.

On the other hand, I have 3dsmax 2013 SDK.
This SDK is made for VS2010 and handle UNICODE strings.

From 3dsmax 2013, any plugin seems to be compiled in UNICODE.
So I have many case where I get data from 3dsmax and put the result in as parameter of a Virtools SDK methods:
let’s say we have such a method in Virtools SDK:

Max2Nmo::CreateObject(const char* name,...)

The code before was (here, GetName() would return a “const wchar_t”):

Max2Nmo* m2n;
m2n.CreateObject(,...)

This code worked before (when non UNICODE plugin was allowed).
Now, both types are mismatching and the compiler is not happy with that.
I have hundreds of errors of this kind (and not all very obvious to solve…).

How can i deal with errors like that (cannot convert ‘const wchar_t *’ to ‘const char *’?

I search the Internet for hours and found this post in Autodesk Discussions Area:
http://area.autodesk.com/forum/autodesk-3ds-max/sdk/problems-linking-plugins-with-2013/
I had the exact same issue as him before I set the project as Unicode (after I read the post).

Has anybody had this problem before and could give an advice ?

Thanks for advance

4 Replies

Thanks for the reply, Claude.

From my post, I have succeded in compiling the code using MaxSdk.
I use 3dsmax built-in functions to convert 3dsmax unicode strings.

Moreover, I want to use the same code for the pre2013 release and 2013 release so I wrote macro definitions to convert strings I pass to Virtools SDK. This way, I can handle the macro definition according the UNICODE preprocessor when compiling, using either UNICODE or not for older versions of 3dsmax.

My current problem is actually these macros. Here is the macro I use to convert MCHAR* to const char*, for example:

#define MCHARP_TO_CONSTCHARP(p)			TSTR(p).ToCStr().data()

I am aware of the dirtyness of these nested conversions but I wanted to do a first secure shot before digging into optimization of these macros.

The weird thing is that doesn’t work as I think it should work. The following line returns some crappy string :

const char *fileName = MCHARP_TO_CONSTCHARP(arg_list[i]->to_string()); // returns a crappy string

although the exact same thing but execute consecutively, returns the correct string:

TSTR lol = TSTR(arg_list[i]->to_string());
CStr lol2 = lol.ToCStr();
const char* lol3 = lol2.data(); // returns the correct string

Can you advice me about this, or show me briefly how you would convert this using your solution ?

you can try this:

add a member to your header:
UINT interfaceCodePage;
 init that in your c-tor:
Interface14 *iface = GetCOREInterface14();
   LANGID langID = iface->LanguageToUseForFileIO();
   UINT interfaceCodePage = iface->CodePageForLanguage(langID);
 then convert your strings:
TSTR unicodeStr(_T("some unicode string"));
   const char* pStr = unicodeStr.ToCP(interfaceCodePage).data();
 guruware

For the record, here is how I solved my question.

I tried to use “guruware” method to convert my strings. I didn’t succeed to do what I needed.
I think I have not very well understand his solution…

Anyway, what I needed was to convert wide char strings (const WCHAR* or WStr) from 3dsmax to simple char strings (const char*) waited by the methods of Virtools SDK.

I used a dirty hack to convert strings on-the-fly each time I passed parameters to Virtools SDK method:

CStr::FromMSTR(3dsmaxWideString)

More, here is a line of code using this conversion (if it can help anybody):

Report(REPORT_LLEVEL,"%s : Saving Skin Data
",CStr::FromMSTR(node->GetName()));

where method Report can only take char* or const char* for strings parameters
However, compiled with UNICODE (as wanted by 3dsmax 2013), node->GetName() returns a const wchar*. I convert it on-the-fly with 3dsmax built-in classes and conversions methods.

I know it is not really clean and remove readability to the code but I can’t figure out another method clean and easy to implement.

Thanks for your help !