private: WebClient ^WebClient1; //******************************* //******************************* //********** FORM LOAD ********** //******************************* //******************************* private: System::Void frmInstallControlCentre_Load(System::Object^ sender, System::EventArgs^ e) { try { //—– CREATE DIRECTORY —– if (!Directory::Exists(TEMP_DOWNLOAD_DIRECTORY)) Directory::CreateDirectory(TEMP_DOWNLOAD_DIRECTORY); //—– DELETE FILE IF IT ALREADY EXISTS —– try { if (File::Exists(TEMP_DOWNLOAD_DIRECTORY + "SomeFile.txt")) { //If file has read only attribute set clear it so that delete […]
All posts by
Sanitising strings for use in SQL statements
If possible don't sanitize your strings. Use parameterized queries instead, as they handle all sanitization. For MS-SQL //Convert single quotes to two single quotes TagDescription = TagDescription->Replace("'", "''"); For MySQL //Convert single quotes to two single quotes TagDescription = TagDescription->Replace("'", "\'");
DLLImport General
[System::Runtime::InteropServices::DllImport(L"user32.dll")] //or using namespace System::Runtime::InteropServices; [DllImport("C:\\Program Files (x86)\\VideoLAN\\VLC\\libvlc.dll")] Note the string is a constant defined at compile time. The default search order will start looking in the directory from which your application was loaded. If you place a DLL there during the install, it will be found. The locations specified in the system PATH variable […]
Convert String To Unicode Values
String Conversion To Unicode Byte Array using namespace System::Text; array<Byte> ^MyArray = Encoding::Unicode->GetBytes(MyString); using namespace System::Text; Encoding ^Unicode1 = Encoding::Unicode; array<Byte> ^UnicodeBytes = Unicode1->GetBytes("1234"); //Produces: 0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00 Convert Unicode Bytes To String using namespace System::Text; MyString = Encoding::Unicode->GetString(MyByteArray); Then To Convert To Unicode Words int Count; UInt16 UnicodeValue; for (Count = 0; Count < UnicodeBytes->Length; Count […]
Reading From Excel
Adding Excel Functionality To Your Project Add Microsoft Excel Reference Menu > Project > Properties > Common Properties > Add Reference > .Net > Microsoft.Office.Interop.Excel (choose the latest version) Add Namespaces using namespace Microsoft::Office::Core; //using namespace Microsoft::Office::Interop::Excel; //To avoid pain with errors due to clashes with “Application” by using this we use the below instead […]
Converting Types
Convert::To Single MySingle = Convert::ToSingle(SomeString); Internationalization – IMPORTANT!!! When converting from strings remember to deal with possible Internationalization issues for countries which use different characters, for instance like commas instead of decimal points – Convert::To doesn’t deal with this! See here
Value Internationalization Issues
Comma Instead Of Decimal Point In countries such as Germany they use commas as decimal points (e.g. -0,136222). So if your program is converting a string like this: String ^sTemp; Single Value; sTemp = “1.234”; Value = Convert::ToSingle(sTemp); What you will actually get is 1234 in Value – the decimal point is ignored. Correctly Handling […]
Making Class Variables and Objects Thread Safe
Simple Locking Approach using namespace System::Threading; Create a flag private: bool ClassObjectsLocked; In your constructor set it up ClassObjectsLocked = false; Then in functions which want to alter values but may be on a different thread while (ClassObjectsLocked) Thread::Sleep(1); In functions which want to read values ClassObjectsLocked = true; … ClassObjectsLocked = false;
Z Order
Force Label To Front MyLabel->BringToFront();
Set Form Position
Set Form To Bottom Left //—– SET OUR POSITION BOTTOM LEFT —– this->Left = Screen::PrimaryScreen->WorkingArea.Left; this->Top = Screen::PrimaryScreen->WorkingArea.Height – this->Height;
