System stützt bei Programm mit EXPAT ab
-
Kann mir jemand sagen, warum mein komplettes System abstützt, wenn ich folgenden Code ausführe?
#include <windows.h> #include <stdio.h> #include <curl/curl.h> #include <expat/expat.h> NOTIFYICONDATA nidTrayIcon; struct memory{ char *content; int size; }; static void elementstart(void *userData, const char *name, const char **atts) { } static void elementend(void *userData, const char *name) { } int parse_data(void *ptr, int size, int nmemb, void *data) { register int realsize = size * nmemb; struct memory *mem = (struct memory *)data; mem->content = (char *)realloc(mem->content, mem->size + realsize + 1); if (mem->content) { memcpy(&(mem->content[mem->size]), ptr, realsize); mem->size += realsize; mem->content[mem->size] = 0; } return realsize; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HICON hMyIcon = LoadIcon(hInstance, "IDI_MYICON"); char *xmlfile = "www.waste-productions.com/community/grabbing.php"; struct memory xml; xml.content = NULL; xml.size = 0; CURL *curl; CURLcode res; XML_Parser p; curl = curl_easy_init(); if(curl) { MessageBox(NULL, "text", "topic", MB_ICONINFORMATION | MB_OKCANCEL | MB_DEFBUTTON1); curl_easy_setopt(curl, CURLOPT_URL, xmlfile); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_MUTE, 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, parse_data); curl_easy_setopt(curl, CURLOPT_FILE, (void *)&xml); curl_easy_perform(curl); curl_easy_cleanup(curl); p = XML_ParserCreate(NULL); XML_SetElementHandler(p, elementstart, elementend); while(!feof((FILE*)xml.content)){ XML_Parse(p, xml.content, xml.size, 0); } nidTrayIcon.cbSize = sizeof(nidTrayIcon); nidTrayIcon.hIcon = hMyIcon; nidTrayIcon.uCallbackMessage = (WM_USER + 1); nidTrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nidTrayIcon.uID = 0x0200; Shell_NotifyIcon(NIM_ADD, &nidTrayIcon); } return 0; }
Wenn ich die while - Schleife auskommentiere, klappt alles wunderbar. Woran liegt es. Der Rechner arbeitet noch einen Moment und spätestens nach 2 Minunten geht nichts mehr. Warum?
flo
-
(FILE*)xml.content
Wo wird denn xml.content ein FILE* zugewiesen?
Und selbst wenn xml.content ein FILE* wäre, wie sollte dann
xml.content = realloc(xml.content) funktionieren?
-
Hm, danke, hatte es aus irgendeinem Beispiel. Aber wenn es so nicht geht: Was würdest Du mir sonst vorschlagen?
flo