Jump to content

alank2

Members
  • Content Count

    115
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by alank2

  1. I am familiar with setting them as an array like this: nhc->CustomHeaders["Authorization"]="mydata"; But could all of them be set from a string formatted as http headers like this authorization:mydata another:value As a single string with a newline between them? If so, how? I see a Data, but it is a const void. (I am using cppbuilder)
  2. This isn't an Embarcadero question per se, but a generic #include <windows.h> and data alignment question. Do the structures defined in windows.h require a specific alignment in the operating system? I have a legacy program that uses 1-byte alignment and the result is a VOLUME_DISK_EXTENTS structure of 24 bytes. If I call DeviceIoControl(Volume, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, ...) with this 24 bytes for the size, it fails, but when packing by 8 bytes resulting in a structure size of 32, it works fine. I solved this by wrapping the windows.h header with pshpack8/poppack, but if the structures require 8 byte alignment, why didn't they do this inside windows.h? #include <pshpack8.h> #include <windows.h> #include <shlobj.h> #include <poppack.h> edit : I found this: https://stackoverflow.com/questions/29518184/64-bit-windows-api-struct-alignment-caused-access-denied-error-on-named-pipe Does the VCL expect a specific alignment (#include <vcl.h>) ?
  3. alank2

    C++ / windows.h and data alignment

    Also, just to add to this, the latest headers in VS2019 do warn of this problem - if the structure packing is changed to something other than 8 and you include <windows.h>, it will give this error. Severity Code Description Project File Line Suppression State Error C2338 Windows headers require the default packing option. Changing this can lead to memory corruption. This diagnostic can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined. Which is easily fixed by wrapping the include like this: #include <pshpack8.h> #include <windows.h> #include <poppack.h>
  4. alank2

    C++ / windows.h and data alignment

    Mine too; I couldn't believe it until I saw the sizeof() some structures were different based on the data packing setting.
  5. alank2

    C++ / windows.h and data alignment

    I thought so too, but see the Remy's link above for: What structure packing do the Windows SDK header files expect? Expect as in it should be set to 8 byte packing BEFORE including the windows.h header. Unlike the vcl.h and presumably fmx.h headers which Remy mentioned above will changing the packing to 8 if it is something different.
  6. alank2

    C++ / windows.h and data alignment

    Try moving it before the vcl.h include and see if that causes it.
  7. alank2

    C++ / windows.h and data alignment

    That is the whole problem I am describing here. They do not. If you change the data alignment from its default of 8, then the structures defined in windows.h will not be correct for what the OS expects. Remy - I usually use #include <pshpack8.h>, but I thoght I'd try your #pragma pack(push,8) and #pragma pack(pop) like this: #pragma pack(push,8) #include <windows.h> #pragma pack(pop) The result is a warning from cppb10.3: [bcc32 Warning] program.cpp(34): W8083 Pragma pack pop with no matching pack push If I remark out the #include, then no warning. Does this mean that MS's header pops more than it pushes leaving my final pop to not have its matching push?
  8. alank2

    C++ / windows.h and data alignment

    Oddly, they don't. If a project's alignment is changed from quad word (8) to something else, there will be issues including windows.h because its structures may not be 8 aligned as the OS expects them to be. I'm glad Embarcadero's copy does force 8 byte alignment, I would have thought that Microsoft's windows.h would have done the same thing, but it doesn't. I only ran into this with some legacy code that needs to be compiled with 1 byte alignment. I'll just be careful to wrap windows.h in a pack 8. Thanks everyone!
  9. If I throw 3 buttons onto a form and set button 1's click to this, it seems the ProcessMessages doesn't fully update all the buttons status. I can run this in bcb6 which is very old, but it behaves as expected, all 3 buttons go to gray/disabled, 3s goes by, then they are become active again, then another 3s delay before the form is available for another click. In cppb10.3 however, something different happens. The first time it is run, the first pass leaves button1 in a non normal state, but not disabled. buttons2/3 unaffected. When it gets to the 2nd pass where it sets the buttons to true, now it updates button1 to visible, and it disables button2 (from the earlier set to false!) The second time it is run, the button1 goes disabled, but buttons 2/3 stay enabled, until the second pass where button1 goes enabled, but buttons 2/3 go disabled. I think ProcessMessages was supposed to process all messages, right? (and yes, the loop where I repeatedly call processmessages every 100ms, does update them more as expected, but not instantaneously) void __fastcall TForm1::Button1Click(TObject *Sender) { //int i1; Button1->Enabled=false; Button2->Enabled=false; Button3->Enabled=false; Application->ProcessMessages(); Sleep(3000); /* for (i1=0; i1<30; i1++) { Application->ProcessMessages(); Sleep(3000/30); }*/ Button1->Enabled=true; Button2->Enabled=true; Button3->Enabled=true; Application->ProcessMessages(); Sleep(3000); }
  10. alank2

    ProcessMessages doesn't seem to update controls

    A colleague of mine suggested changing DoubleBuffered and this seems to change the behavior enough to fix it! edit: well, it fixes it in debug mode, but not always in release mode so it isn't a fix after all.
  11. alank2

    ProcessMessages doesn't seem to update controls

    This really does have to do with the highlighting and styling of the button. If I make a loop that disables and enables a button when clicking it, sometimes it won't change states if I am still hovering over it with the mouse. Is there a way to disable the highlighting that happens when you simply hover over a button?
  12. alank2

    ProcessMessages doesn't seem to update controls

    Fr0sT.Brutal that works - the optimal delay is above 300ms: #define DELAY 325 Label1->Caption="off"; Button1->Enabled=false; Button2->Enabled=false; Button3->Enabled=false; Sleep(DELAY); Application->ProcessMessages(); Sleep(3000); Label1->Caption="on"; Button1->Enabled=true; Button2->Enabled=true; Button3->Enabled=true; Sleep(DELAY); Application->ProcessMessages(); Sleep(3000); Label1->Caption="";
  13. alank2

    ProcessMessages doesn't seem to update controls

    DelphiUdIT - I tried the below (with and without the processmessages calls) and it still has the issue Button1->Enabled=false; Button1->Update(); Button2->Enabled=false; Button2->Update(); Button3->Enabled=false; Button3->Update(); // Application->ProcessMessages(); Sleep(3000); Button1->Enabled=true; Button1->Update(); Button2->Enabled=true; Button2->Update(); Button3->Enabled=true; Button3->Update(); // Application->ProcessMessages(); Sleep(3000);
  14. alank2

    ProcessMessages doesn't seem to update controls

    The Sleep(x) is just a replacement for some other process that will keep execution in a method. The workflow is something like this: User clicks a button. I want to disable all buttons while this process runs so they are unable to click any of them, so I change them to disabled. Then I want to make sure that the screen is updated before I call whatever it is that may take seconds to run. Previously I could just set them to enabled=false and call ProcessMessages() once and it would update properly. I realize that putting the "seconds to run" is more ideal in a thread, but that adds creating and managing a thread which I don't want to have to do for every process that takes a few seconds. Essentially I am looking for a function that will make sure the UI is fully updated before a period of time where it won't be updated. I tried using calling Repaint for all 3 buttons before a ProcessMessages, but it didn't work. Whatever is different between versions, perhaps changing a property from true to false takes a number of things to occur in sequence that rely on each other?
  15. alank2

    ProcessMessages doesn't seem to update controls

    Thanks Remy; sometimes I have a synchronous process and I want to make sure some VCL elements are updated beforehand. This always worked fine in bcb6. What could cause the Enabled change to _not_ create an immediate pending message?
  16. I have them set to (left, top, width, height) 45, 80, 500, 320 in the form designer. I also have borderstyle=none, position=designed, but at runtime if I evaluate them they are 45, 80, 516, 358 so the width and height were altered by something. I remember a thing called scale for VCL, but I don't see it present in the FMX form. Any ideas why the width/height changed? Can I prevent it without forcing the width/height in the form constructor (which does work)?
  17. This is a very strange issue so I thought I'd see if anyone here has experienced anything similar: I have had a release of software at multiple locations, multiple systems, and never saw the error before 6/8 at any site including the site now having the problem (it was running fine there for months). 2023-06-08 02:02:16.879 ERROR: Unsupported media file myvideo.wmv (e020212) (ignore the e020212, this is my error code to locate where the error is) Then on 6/8 and after, at only one specific location, all of the computers at this location, are giving this error only when they restart their software at 2am. It will fail with the above exception. If you then restart it manually later on, it will load fine, only to repeat the same problem the next day.= at 2am. //prompt animation try { FScalePrompt->MediaPlayer1->FileName="c:\\programdata\\myprog\\myvideo.wmv"; } catch(Exception &exception) { swprintf(ws1, L"ERROR: %ls (e020212)", exception.Message.c_str()); DialogMessageBox(ws1); goto fail1; } Any ideas on why this exception would be thrown only at 2am when the software restarts itself and then not at other times of the day? The software is launched by another process and it is closing itself down fine according to the log: 2023-06-08 02:01:46.942 Exiting 2023-06-08 02:02:13.473 Starting 2023-06-08 02:02:16.879 ERROR: Unsupported media file scaleitem.wmv (e020212)
  18. If I create a new DLL, it prompts me with a dialog that allows me to set these things: Can you change these settings/target framework on an existing project? If so, where?
  19. That is what I wondered; thanks for posting - I too use Beyond Compare, it is great!
  20. So as a test I tried to set a TEdit to a UTF-8 sequence and it ended up as a series of characters and not the smile face I was testing. If I convert it first to a wide string and then assign the wide string it works: MultiByteToWideChar(CP_UTF8, 0, "\xf0\x9f\x98\x82", -1, ws1, 1024); Is there a way to make it recognizing a narrow string assignment as UTF-8 - some sort of code page setting in the application maybe? or will it not do that?
  21. alank2

    Assigning UTF-8 to a control

    Thank you; I'll check it out!
  22. alank2

    Assigning UTF-8 to a control

    Thanks for the advice. On Friday I discovered an unexpected thing with sprintf/swprintf that string conversion from narrow to wide and vice versa uses a buffer that is limited to 512 bytes. I traced this down to the source code (in vprinter.c) to see that that is what it is doing. I typically think of sprintf/swprintf as commands as being designed to emit data directly as to not be limited by a buffer size, but clearly that isn't the case. Trying to convert a larger string will corrupt a program from a buffer overrun. Why they didn't just code it to do a simple bufferless conversion in place does not make sense to me, especially since they aren't really properly converting between UTF-8 and UTF-16 anyway, but it is what it is. I found the WIN32 API functions MultiByteToWideChar and WideCharToMultiByte, but at the same time I've been thinking about how I can better handle string conversion and variable width strings in general to support UTF-8/UTF-16 better.
  23. alank2

    Assigning UTF-8 to a control

    C++ Builder
  24. alank2

    Assigning UTF-8 to a control

    I suppose anywhere; I just wondered if you could assign a char* string that is UTF-8 and have it recognize it that way.Insert other media
  25. I've been using: unsigned char data[]={ 255,216,255,225,7,132,69,120,105,102,0,0,77,77,0,42,0,0,0,8,0,12,1,0,0,3,0,0,0,1,1,144,0,0,1,1,0,3,0,0,0,1,1,11,0,0,1,2,0,3,0,0,0,3,0,0,0,158,1,6,0,3,0,0,0,1,0,2,0,0,1,18,0,3,0,0,0,1,0,1,0,0,1,21,0,3,0,0,0,1,0,3,0,0,1,26,0,5,0,0,0,1,0,0,0,164,1,27, 0,5,0,0,0,1,0,0,0,172,1,40,0,3,0,0,0,1,0,2,0,0,1,49,0,2,0,0,0,31,0,0,0,180,1,50,0,2,0,0,0,20,0,0,0,211,135,105,0,4,0,0,0,1,0,0,0,232,0,0,1,32,0,8,0,8,0,8,0,10,252,128,0,0,39,16,0,10,252,128,0,0,39,16,65,100,111,98,101,32,80,104,111,116,111,115,104, ... }; But it is a large amount of data and I wonder if there is a better way?
×