EdgarsK Posted February 12, 2010 Report Share Posted February 12, 2010 Sveiki :) es lietoju visual c++ 2008 express studiju, problema man sekojosha :) private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this->openFileDialog1->Filter = "pdf faili|*.pdf"; this->openFileDialog1->Title = L"Izvēlies savu PDF failu"; if(this->openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK){ System::IO::StreamReader ^ sr = gcnew System::IO::StreamReader(this->openFileDialog1->FileName); System::String ^ s = "copy \""+this->openFileDialog1->FileName+"\" C:/instance.pdf"; system(s); sr->Close(); } } problēma sekojoša - Cannot convert a managed type to an unmanaged type - tur kur definēju "s" kā lai pareizi pārkonvertēt to 's' par charu ? s_char funkcija nav :/ nesaprotu kapec. Quote Link to comment Share on other sites More sharing options...
2easy Posted February 12, 2010 Report Share Posted February 12, 2010 (edited) varbūt nemaz nevajag definēt to s? ;) system("copy \""+this->openFileDialog1->FileName+"\" C:/instance.pdf"); vsp šādos gadījumos error message ir vnk jāiekopē googlē un jānospiež podziņa "Es ticu veiksmei!" :)) http://www.codeproject.com/KB/dotnet/managed_unmanaged.aspx?df=100&forumid=2227&exp=0&select=1121927 Edited February 12, 2010 by bubu mazāk uzbraucienus Quote Link to comment Share on other sites More sharing options...
bubu Posted February 12, 2010 Report Share Posted February 12, 2010 Tas nav C++, tas ir C++/CLR, kurai ir lielas atšķirības no C++. Problēma tev ir tāpēc, ka gribi System::String^ tipa objektu padot vietā, kur jāpadod const char* tipa izteiksme. Tās ir divas dažādas pasaules - menedžētā un nemenedžētā. Tā nevar. Lai pārvērstu System::String uz const char*, kuru sagaida system funkcija jādara ir sekojoši: http://support.microsoft.com/kb/311259 Vai, protams, labāks variants - nelietot system, bet normālu Process klasi, no System.Diagnostic neimspeisa, ja jau programmēt .NET'ā. Tad nevajadzēs neko pārvērst uz const char*. Un vilabāk - lai kopētu failus vajag lietot File.Copy no System.IO neimspeisa. RTFM! Topikam nav nekāda sakara ar pārlūkprogrammu vidēm/valodām. Nākamreiz izvēlies atbilstošāku sadaļu. Quote Link to comment Share on other sites More sharing options...
2easy Posted February 12, 2010 Report Share Posted February 12, 2010 (edited) tad pēc tā ms kb article sanāk, ka viņam vajadzētu šādi izsaukt? system(PtrToStringChars("copy \""+this->openFileDialog1->FileName+"\" C:/instance.pdf")); lai arī tas nav ieteicamais file copy veids, bet tā string pārveidošana ta strādātu ja? bubu, tev gan humora izjūta tāda interesanta. tas vsp nebija nekāds uzbrauciens Edited February 12, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted February 12, 2010 Author Report Share Posted February 12, 2010 es izdariju sekojoshi :) System::String ^ s = "copy \""+this->openFileDialog1->FileName+"\" \"C:\\pdfExport\\out.pdf\""; array<Byte> ^chars = System::Text::Encoding::ASCII->GetBytes(s); pin_ptr<Byte> charsPointer = &(chars[0]); char *nativeCharsPointer = reinterpret_cast<char *>(static_cast<unsigned char *>(charsPointer)); std::string native(nativeCharsPointer, chars->Length); Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted February 12, 2010 Author Report Share Posted February 12, 2010 (edited) Topikam nav nekāda sakara ar pārlūkprogrammu vidēm/valodām. Nākamreiz izvēlies atbilstošāku sadaļu. tā tomēr nav php, bet gan cita programmēšanas valoda Edited February 12, 2010 by EdgarsA Quote Link to comment Share on other sites More sharing options...
2easy Posted February 12, 2010 Report Share Posted February 12, 2010 (edited) es izdariju sekojoshi :) System::String ^ s = "copy \""+this->openFileDialog1->FileName+"\" \"C:\\pdfExport\\out.pdf\""; array<Byte> ^chars = System::Text::Encoding::ASCII->GetBytes(s); pin_ptr<Byte> charsPointer = &(chars[0]); char *nativeCharsPointer = reinterpret_cast<char *>(static_cast<unsigned char *>(charsPointer)); std::string native(nativeCharsPointer, chars->Length); njaa vēl sarežģītāk laikam nevar izdomāt, kā no viena stringa dabūt citu tādu pašu stringu :D:D:D bet galvenais jau ka strādā ;) bubu laikam domāja šādi :D Topikam nav nekāda sakara ar pārlūkprogrammu vidēm/valodām. Nākamreiz izvēlies atbilstošāku sadaļu. Edited February 12, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
bubu Posted February 12, 2010 Report Share Posted February 12, 2010 tā tomēr nav php, bet gan cita programmēšanas valoda Sadaļa ir par pārlūka puses programmēsanas valodām, kuras tu lieto browserī (java, flash, utml). Pareizais kods ir: System::IO::File::Copy(this->openFileDialog1->FileName, "C:\\pdfExport\\out.pdf"); Quote Link to comment Share on other sites More sharing options...
2easy Posted February 12, 2010 Report Share Posted February 12, 2010 (edited) man laikam sāktos depresija, ja vnk copy() vietā būtu jāraksta System::IO::File::Copy() :D:D:D es jau saprotu, ka namespace vajag, lai nebūtu function name kolīzijas, bet nju tas ir traki gari anyway ja es taisītu savu c++ valodu, tajā failu varētu nokopēt ar funkciju fcp() - file copy cerams, neviens to neuztver pārāk nopietni ^^ Edited February 12, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
bubu Posted February 12, 2010 Report Share Posted February 12, 2010 Tāpēc ir izdomāti using namespace System::IO. Un pēc tam raksti File::Copy(...); Ja tev patīg visi tavi fcp, abc, xyz, tad paskaties uz Perlu. Tur tu īsumīsi varēsi uzrakstīt ļoti daudzas lietas. Quote Link to comment Share on other sites More sharing options...
2easy Posted February 12, 2010 Report Share Posted February 12, 2010 (edited) njaa 3x burtu kombinācijas ir pašas izteiksmīgākās :D:D:D yep, perls tiešām ir elīts. ir ko pamācīties Edited February 12, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
waplet Posted February 12, 2010 Report Share Posted February 12, 2010 nevar tač vairākus jūzing namespace norādīt vane? Quote Link to comment Share on other sites More sharing options...
bubu Posted February 12, 2010 Report Share Posted February 12, 2010 Protams var. Quote Link to comment Share on other sites More sharing options...
2easy Posted February 13, 2010 Report Share Posted February 13, 2010 un ja dažādos namespace ir funkcija ar to pašu nosaukumu, tad arī var? ;) Quote Link to comment Share on other sites More sharing options...
bubu Posted February 13, 2010 Report Share Posted February 13, 2010 Arī var. Tikai tad, kad lietosi to, dabūsi erroru par ambigous function call. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.