How to download a file from the internet? [SOLVED]
-
On 03/10/2014 at 11:54, xxxxxxxx wrote:
I'm afraid I have no idea about those.
One thing that I've noticed is that VS will throw missing ';' or missing ')'; error messages if you forget the closing brace '}' somewhere in your code.
VS apparently doesn't know how to check your scoping {} braces very well. And it throws those kinds of misleading error messages. And sends you on a wild goose chase if you forgot to close your scope with an '}' in your code.I doubt that's why you're getting those error though.
-ScottA
-
On 03/10/2014 at 12:00, xxxxxxxx wrote:
I also doubt that because I do all my initial development in Xcode and Xcode is excellent at balancing { }, " " and ( )
Damn!!! It would be so fine if it was just a matter of moving the source and res folder from my Mac project to the VS project -
On 05/10/2014 at 15:16, xxxxxxxx wrote:
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>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>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\msxml.h(1436) : error C2143: syntax error : missing ')' before 'constant'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\msxml.h(1436) : error C2143: syntax error : missing ';' before 'constant'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\msxml.h(1436) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\msxml.h(1436) : error C2238: unexpected token(s) preceding ';'I think in one of your files you are including <windows.h> or some other header that includes this (probably from the curl libs). Then after than include you are then including some c4d headers, perhaps "c4d.h". You will now get conflicts with windows when compiling.
Basically the issue is that you should not mix any non C4D header includes in a file that uses C4D.
What I would do is have a seperate CPP file that does all the calls to libcurl. Do not have any C4D includes in this at all. Create a header file for that CPP that has standard C++ variables. DownloadFile(const char *url, int len). Then implement this method in the CPP file to call all the libcurl required functions, this CPP file should not call any C4D code or have any C4D headers in it. Its just for libcurl. There is nothing else at all in the header file either.
Then in your C4D files you can include this header to call the methods. Or you could ignore the header file and forward declare these methods directly in your c4d file.
-
On 05/10/2014 at 16:02, xxxxxxxx wrote:
Oh shoot. You're right Kent.
Sorry about that Rui. I forgot to tell you about the order of the includes.
The C4D includes always need to be placed after your STL stuff.If you have your C4D includes listed first. That could explain the errors Rui.
Try putting #include <curl.h>afterbefore your C4D includes.
It works fine me.-ScottA
-
On 05/10/2014 at 16:13, xxxxxxxx wrote:
I did found that it had to be something to do with the #include <curl.h> just a while ago. I was commenting out each line of #include (and correspondent dependent code) and the errors stopped when I commented the #include <curl.h> line.
I do have my #include <curl.h> after my #include "c4d.h".
My #include's are like this:#include "c4d.h" #include "serialization.h" #include <stdio.h> #include <curl.h> #include <sys/stat.h> #include <time.h> #include <sstream> #include <fstream> #include <iostream> #include <string> #include <stdlib.h>
I will try out creating an individual .cpp file for all my curl stuff tomorrow. It is quite late here and I must go to bed now.
I will let you guys know how it went. Thank you all -
On 05/10/2014 at 16:38, xxxxxxxx wrote:
Note: Order of header inclusion can be very important. Typically, you want to include standard C++ headers first, SDK headers next, and then third-part headers last (just as a rule of thumb). Even then, you should juxtapose them during testing/debugging to resolve issues.
Another note (that I learned the hard way) : Never, ever include headers in headers. Include them in the source file (.cpp). It avoids any deeply-nested issues that may occur.
-
On 05/10/2014 at 16:54, xxxxxxxx wrote:
Doh!
I meant put your STL stuff before your c4d includes.
Sorry about that. My brain must be fried from trying to use the Mudbox SDK.
If you think the C4D SDK is bad...try using the Mudbox SDK. :zipper_mouth:curl compiles fine for me when it's inside of a C4D plugin.
However. I do get unresolved errors from this code if I use it inside of a plugin: curl = curl_easy_init();
Apparently VS can't find this method for some strange reason.When I tested your code and the curl examples. I tested them in a raw C++ project. Not inside of a C4D plugin.
There seems to some more hoops to solve if you want to run the curl code inside you're plugin.
You might be better off running it in a raw C++ project. Then having your C4D plugin execute your Raw C++ curl code.Fun...ain't it.
-ScottA
-
On 05/10/2014 at 18:27, xxxxxxxx wrote:
Easy enough to create a separate raw C++ project by using it as a lib. That is how I added zlib and other third-party C++ support. Doesn't always work, mind you. I was unable to (and it seems that noone else has been able either) to include the PointCloud library and not crash C4D - mainly because it allows multiple inheritances and exceptions, the former being verbotten in C4D.
-
On 05/10/2014 at 19:36, xxxxxxxx wrote:
@Robert won't any library work fine if you compile and work with it as a dynamic link library? or Cinema 4D will have problems in binary code exceptions in an external dll
-
On 06/10/2014 at 02:33, xxxxxxxx wrote:
I will try first sorting the #include's.
Why is it that it compiles and works just fine in Xcode but not in Visual Studio? -
On 06/10/2014 at 03:18, xxxxxxxx wrote:
Ok, no amount of shuffling around makes the errors go away
I will try to make the curl stuff into a separate .cpp file now. -
On 06/10/2014 at 05:33, xxxxxxxx wrote:
Good news and bad news.
The good news are that I no longer get the errors I was getting.
The bad news are that I now get new errors that I really don't understand:1>Link:
1> Creating library C:\Program Files\MAXON\CINEMA 4D R14\plugins\PolyPaintTag\obj\PolyPaintTag\Win32_Release\PolyPaintTag.cdl.lib and object C:\Program Files\MAXON\CINEMA 4D R14\plugins\PolyPaintTag\obj\PolyPaintTag\Win32_Release\PolyPaintTag.cdl.exp
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_cleanup referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_setopt referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_init referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>C:\Program Files\MAXON\CINEMA 4D R14\plugins\PolyPaintTag\PolyPaintTag.cdl : fatal error LNK1120: 4 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:05.36
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
1>Link:
1> Creating library C:\Program Files\MAXON\CINEMA 4D R14\plugins\PolyPaintTag\obj\PolyPaintTag\Win32_Release\PolyPaintTag.cdl.lib and object C:\Program Files\MAXON\CINEMA 4D R14\plugins\PolyPaintTag\obj\PolyPaintTag\Win32_Release\PolyPaintTag.cdl.exp
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_cleanup referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_setopt referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>access_url.obj : error LNK2019: unresolved external symbol __imp__curl_easy_init referenced in function "bool __cdecl check_online(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?check_online@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>C:\Program Files\MAXON\CINEMA 4D R14\plugins\PolyPaintTag\PolyPaintTag.cdl : fatal error LNK1120: 4 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:05.36
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========Like before, it all works fine in Xcode.
-
On 06/10/2014 at 07:56, xxxxxxxx wrote:
you should link to the curl library, in VS , project-> properties-> linker-> general -> Additional library directories , put /lib folder of the curl lib
and in the linker->input->Additional dependencies , put the curl library name, example:the_curl_library_name.lib
-
On 06/10/2014 at 09:15, xxxxxxxx wrote:
I found the source of the unresolved symbols problem I had with: **curl = curl_easy_init();
** I installed the 32 bit version of curl. And my C4D plugin was set to Debug | x64.
When I changed my C4D plugin to Debug | Win32. It works. And I can write curl code inside of my plugin's Execute() method now without any errors.
So I guess that's very important!!I tested it using your small curl code Rui. And it seems to work fine.
I have not yet figured out how to convert the output of the code into GePrint compatible code yet:
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
But it does run. And it does grab a file from the internet without errors. When executed from my C4D plugin.NOTE:
Since C4D plugins are basically .dll based programs.
You have to put the built libcurl.dll file in your main Maxon folder where the .exe files are.-ScottA
-
On 06/10/2014 at 09:49, xxxxxxxx wrote:
But my plugins are for selling. Must I force people to place the libcurl.dll files next to the exe files?
Or is this just for compiling?
Also, to compile WIN32 and WIN64 versions must I install both versions of curl?!? -
On 06/10/2014 at 10:17, xxxxxxxx wrote:
I'm pretty sure there's some plugin developers that sell plugins that require the users to add a .dll to the MAXON folder.
It's really not a big deal. Because the folder is easy to find.Based on my results. I'm guessing that you'll have to install both 32 and 64 bit versions.
I personally wouldn't bother with 32 bit plugins anymore.I still can't get C4D to return a proper result yet
This is the relevant code that's in my CommandData plugin:#include <stdio.h> #include <curl.h> #include <iostream> #include <string> #include "c4d.h" #include "c4d_symbols.h" Bool SimplePlugin::Execute(BaseDocument *doc) { CURL *curl; CURLcode res; char *usrpass="my_username:my_password"; char *buffer="1234567890"; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/robots.txt"); curl_easy_setopt(curl, CURLOPT_USERPWD , usrpass); curl_easy_setopt(curl, CURLOPT_READDATA, buffer); curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL); //Perform the request //res will get the return code res = curl_easy_perform(curl); String r = curl_easy_strerror(res); GePrint(r); //<--- Failed writing received data to disk/application /* Check for errors */ if(res != CURLE_OK) { GePrint("curl has failed"); //<-- The console also prints this..curl has failed :-( //Always cleanup curl_easy_cleanup(curl); return FALSE; } } EventAdd(); return TRUE; }
Everything seems to be working. And I'm pretty sure it's reading the HTML file.
But I can't get C4D to use it yet.-ScottA
-
On 06/10/2014 at 10:52, xxxxxxxx wrote:
After a quick spin around the internet.
I found a converter that will convert the data into strings.This is the relevant code from my C4D CommandData plugin.
It grabs the text from a website using curl. And displays it to the C4D Console:#include <stdio.h> #include <curl.h> #include <iostream> #include <string> #include "c4d.h" #include "c4d_symbols.h" static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string* )userp)->append((char* )contents, size * nmemb); return size *nmemb; } Bool SimplePlugin::Execute(BaseDocument *doc) { CURL *curl; CURLcode res; std::string readBuffer; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/robots.txt"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); res = curl_easy_perform(curl); curl_easy_cleanup(curl); //Convert the string to a String compatible with C4D String convertedToC4D = readBuffer.c_str(); GePrint(convertedToC4D); } EventAdd(); return TRUE; }
phew!...this is too much like work.!
Wink
[URL-REMOVED]
Why do I feel like Dr. Frankenstein?-ScottA
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 06/10/2014 at 11:26, xxxxxxxx wrote:
So, I don't need to bother creating .cdl files anymore?
Why, oh why isn't developing and compiling stuff in VS as easy as with Xcode?!?!? -
On 06/10/2014 at 12:33, xxxxxxxx wrote:
You still need the .cdl files and your usual plugin stuff.
The .cdl files are for running your plugin.
The libcurl.dll file is how C4D itself finds the curl libraries.This is my understanding of how it works:
When you set up the curl paths in VS. You're telling VS where to find the curl libraries. But you haven't told C4D (the program) where to find them.
Maxon has set up the c4d program to look for the C4D based .dll files in a specific folder/folders. So that our plugins can make use of them.
The C4D program is basically a plugin reader program.
It grabs the .dlls from where it was told to grab them. The ones that ship with it, and the ones built in and our plugins.
When you bring in an alien .dll file. C4D has not been told where and how to use it.
But when C4D launches. It's able to read a .dll file if it's in the MAXON folder.As an example. QT is a very popular library people use for GUI stuff.
The various programs they use QT libraries on have no clue what a QT.dll is. QT.dll is an alien file.
So in addition to telling VS how to link the QT libraries to the code they're writing. They also have to put a copy of the .dll's in the source files when they package up their program to send to the users.
If you look at the files that people include in their programs. If it uses a QT based GUI. And the they did not compile QT as static. Then you should see somewhere in the source files a few QT.dll files.
In c4d. The place where these alien .dll files go is the MAXON folder.I think most of that is correct. But don't take it as gospel.
I'm still learning how things work myself.-ScottA
Edit- There's probably a way to put the libcurl.dll in your plugin folder rather than the MAXON folder.
And have C4D somehow read it from there. But I have never done it. People like Robert might know how. -
On 06/10/2014 at 13:47, xxxxxxxx wrote:
Umm...hmmm.
I just re-wrote the plugin from scratch. And this time it runs fine if I put the libcurl.dll file in my plugin folder.
I have no idea why it wouldn't run before. So you might not need to put libcurl.dll in the MAXON folder.Sorry about any confusion Rui.
This is the first time I've fooled around with .dll files in my c4d plugins.-ScottA