Return string to Python
-
On 30/10/2013 at 08:58, xxxxxxxx wrote:
Thanks very much.
I'll try and let you know. -
On 30/10/2013 at 09:17, xxxxxxxx wrote:
Sorry, I get the following error.
Maybe because I need to change main.cpp?1>Main.obj : error LNK2005: "int __cdecl PluginStart(void)" (?PluginStart@@YAHXZ) already defined in niklas.obj 1>Main.obj : error LNK2005: "void __cdecl PluginEnd(void)" (?PluginEnd@@YAXXZ) already defined in niklas.obj 1>Main.obj : error LNK2005: "int __cdecl PluginMessage(long,void * )" (?PluginMessage@@YAHJPAX@Z) already defined in niklas.obj 1> Creating library D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\obj\cinema4dsdk\Win32_Release\cinema4dsdk.cdl.lib and object D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\obj\cinema4dsdk\Win32_Release\cinema4dsdk.cdl.exp 1>D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\cinema4dsdk.cdl : fatal error LNK1169: one or more multiply defined symbols found ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
-
On 30/10/2013 at 09:19, xxxxxxxx wrote:
Note, I am not yet in full control / understanding of all switches in visual studio 2010 Express.
-
On 30/10/2013 at 09:31, xxxxxxxx wrote:
I now see what I did wrong.
It is now functioning!
Thanks, I 'll study it in detail. -
On 01/11/2013 at 07:48, xxxxxxxx wrote:
It is progressing.
I now read the cinema 4d serial number, calculate the sha256 and compare it with the contents of the license file.
However, when I close cinema 4d, I get a MS C++ runtime error:
Program: cinema 4d r14\ cinema 4d 64 bit.exeR6025
- pure virtual function call.What to do?
I get only warnings from the compiler / linker
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc 1>d:\program files\maxon\cinema 4d r14\plugins\cinema4dsdk\niklas 3.cpp(154) : warning C4267: 'argument' : conversion from 'size_t' to 'LONG', possible loss of data 1> Creating library D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\obj\GetLicense\x64_Release\GetLicense.cdl64.lib and object D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\obj\GetLicense\x64_Release\GetLicense.cdl64.exp 1> cinema4dsdk.vcxproj -> D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\GetLicense.cdl64 ========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
-
On 01/11/2013 at 09:42, xxxxxxxx wrote:
At what point is the C string being deallocated? It is possible that it happens at a time the function-table is
invalid already. Try to create a Python copy of the string and not store it directly.> c_string = MyLib . SomeFunction(c4dlicense)
> string = str(c_string) -
On 01/11/2013 at 11:32, xxxxxxxx wrote:
It seems that if I add something outside cinema 4d to your routine, the error is given.
E.G. when I want to write some debug information to an external file and add
ofstream myfile;
the error is given.
So without this line, no error, with the line the error is given.
The same is true when I add my own routine, the error is given.DLLEXPORT char* GetAppLicense() { ofstream myfile; //gives the error! GePrint ("Start GetAppLicense."); SerialInfo info; GeGetSerialInfo(SERIALINFO_MULTILICENSE, &info); if (!info.nr.Content()) { GeGetSerialInfo(SERIALINFO_CINEMA4D, &info); } #if OUTPUT_CALLS GePrint("GetAppLicense() : allocating memory for string \"" + info.nr + "\"."); #endif char* output = info.nr.GetCStringCopy(); return output; }
-
On 01/11/2013 at 11:44, xxxxxxxx wrote:
Could you please add the /EHsc compiler option to your project settings and retry?
-
On 01/11/2013 at 12:21, xxxxxxxx wrote:
I change it using:
- Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
- Click the C/C++ folder.
- Click the Code Generation property page.
- Modify the Enable C++ Exceptions property.
Should I also add some code and if so what code?
MS gives as an example:
See also http://msdn.microsoft.com/en-us/library/1deeycx5(v=vs.90).aspx// compiler_options_EHA.cpp // compile with: /EHa #include <iostream> #include <excpt.h> using namespace std; void fail() { // generates SE and attempts to catch it using catch(...) try { int i = 0, j = 1; j /= i; // This will throw a SE (divide by zero). printf("%d", j); } catch(...) { // catch block will only be executed under /EHa cout<<"Caught an exception in catch(...)."<<endl; } } int main() { __try { fail(); } // __except will only catch an exception here __except(EXCEPTION_EXECUTE_HANDLER) { // if the exception was not caught by the catch(...) inside fail() cout << "An exception was caught in __except." << endl; } }
-
On 01/11/2013 at 12:23, xxxxxxxx wrote:
The warning is gone, but the error is still there.
1>d:\program files\maxon\cinema 4d r14\plugins\cinema4dsdk\niklas 5.cpp(162) : warning C4267: 'argument' : conversion from 'size_t' to 'LONG', possible loss of data 1> Creating library D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\obj\GetLicense\x64_Release\GetLicense.cdl64.lib and object D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\obj\GetLicense\x64_Release\GetLicense.cdl64.exp 1> cinema4dsdk.vcxproj -> D:\Program Files\MAXON\CINEMA 4D R14\plugins\cinema4dsdk\GetLicense.cdl64 ========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
-
On 01/11/2013 at 12:35, xxxxxxxx wrote:
Great, the warning was supposed to drop. Does it still crash?
-
On 01/11/2013 at 12:44, xxxxxxxx wrote:
Yes, sorry. The error is still there.
Also, it does not crash.
The call to python is working, I do get a return value and the code is executed ok.
Except when i close down cinema 4d, I get the error message.
Not while working? -
On 01/11/2013 at 14:50, xxxxxxxx wrote:
There is NO error when comp and link in 32 bit debug mode.
32 release mode give an error.I cannot debug in 64 bit because the linker cannot find 'kernel32.lib'?
1>------ Build started: Project: GetLicense, Configuration: Debug x64 ------ 1> niklas 5.cpp 1>d:\program files\maxon\cinema 4d r14\plugins\cinema4dsdk\niklas 5.cpp(160) : warning C4267: 'argument' : conversion from 'size_t' to 'LONG', possible loss of data 1>LINK : fatal error LNK1104: cannot open file 'kernel32.lib' ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
And again, all seems to be functioning correctly.
Only when I exit cinema, the error pops up?Also when debugging I see a lot of:
"Cannot find or open the PDB file" -
On 06/11/2013 at 08:39, xxxxxxxx wrote:
Thanks for sending me the code. I'm currently examining it. What I can say is that the error comes
not from my original code, but from your use of the standard library. Though I can't tell you at the
moment why and how to fix it.Maxon does not officially support using the standard library, yet you require it. I've successfully
made use of the standard library myself in plugins, so I am interested in where the issue is.Best,
-Niklas -
On 08/11/2013 at 10:38, xxxxxxxx wrote:
Ok, thanks for the support.
I hope you can solve it quickly.
We want to bring out a new plugin this month, but we still have to decide how to protect.
Using easily crack-able python, or a bit more difficult C++ library.Did you ever called C++ from python using the standard library?
Regards, Pim
-
On 10/11/2013 at 05:25, xxxxxxxx wrote:
Hi Pim,
if you don't need the Cinema 4D Api, it is really no problem to create a DLL which makes use of the
C++ standard library. The problem is that the Cinema 4D Api and the use of the std library are
conflicting sometimes. Unfortunately I don't have a solution to your problem yet (which uses the
Cinema 4D Api).In case you do not need the C4D Api, you can create a new VC++ project from scratch (without
the cinema4sdk as the original project).Best,
-Niklas -
On 10/11/2013 at 08:55, xxxxxxxx wrote:
Hi Niklas,
Correct, I now created a C++ function with no C4D in it at all and just call it.
No problem there.So like you say " The problem is that the Cinema 4D Api and the use of the std library are
conflicting sometimes".
However, it would be nice to mix C4D and standard C++ in one routine and call it from Python.
If you fix it one day, please let me know.
I continue on the above road (not mixing C4D and standard C++).
Thanks for the support.Pim