alank2
Members-
Content Count
145 -
Joined
-
Last visited
-
Days Won
1
Everything posted by alank2
-
I am using TNetHTTPClient and I am getting back a status code 200 from the request. When I look at the value in StatusText however, it is empty instead of the OK I expected. I did the same request with postman and looking at the raw status line the OK is present. Has anyone else experienced this? I did look in System.Net.HttpClient.Win.pas and see that it does a: Result := ReadHeader(FWRequest, WINHTTP_QUERY_STATUS_TEXT); edit: this was with 11.3
-
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
Thank you for the help rvk (and everyone in this thread!), instead of a loose end I now have a reason for why it is doing what it does. Going forward I'll ignore the status text always and just go with the result code. What made me nervous about this is that the status code itself is also retrieved from the same function as text and then later converted to an integer, so I'm not sure why this is an issue for status text, but not status code. Hopefully going forward it won't be. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
I noticed this as well. I don't usually use the /install or /uninstall options but instead use Inno setup and sc.exe to stop/remove/install/start services. I usually (and I don't think it is the right way as Remy pointed out to me in another thread, I still need to do some testing on it to change) implement a ServiceExecute with a message loop that runs until the service is stopped, so something like this; while (!Terminated) //do not quit if process is running until it is finished { ServiceThread->ProcessRequests(true); Sleep(250); } If I add this to the above service, it doesn't add the OK from local execution of "project1 /install", but it does for some reason for "project1 /uninstall". How would you do this? Exactly. I know the local system account does change the environment that a service runs it as far as rights go, but I don't know what this would have a change in the WinHttpQueryHeaders(). -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
Good thinking!!! This is it. When the service is configured to use "Local System Account" It does NOT report "OK". If I change it to administrators or my own user name, it does report "OK". Any ideas why local system account can't retrieve the status text even though it does properly retrieve the status code? -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
Yes. I'll give this a try. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
Here is some test code that shows it. From the application (returns OK properly): From the service (does not return OK properly, but an empty string instead): result 200 '' The service saves to a file "c:\5\log.txt", but you can change where it saves it if you run the code. Build the service, admin cmd prompt, go win32\debug and run project1 /install, then run net start service1. it will create the c:\5\log.txt (or what you renamed it to) with the results of the GET to google. To uninstall just do net stop service1 followed by a project1 /uninstall. test.zip -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
My big concern isn't the status string, I can ignore it. My concern is that if that is not right, why, and what else might not be right. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
Tested it on 10 and 11 same result. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
I created a new 10.3.3 service application and put the code in - it does NOT return OK. The same code in a standalone application does return OK. I'll come up with a sample project I can post to see if others can reproduce the issue. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
It is not consistent - I have another API that I use in the same service and it returns OK just fine, but if I do a GET @ https://google.com, it will not return OK. I then tried a new application (not service) with the same code (GET @ https://google.com), it works fine and returns OK. I rebuilt the project on 10.3.3, 11.3, and 12.2, and all of them return an empty string instead of OK. I wonder if it being a service has something to do with it. Next up I'll build a new service project service and see if the issue occurs with that. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
This is a cut from the postman console which shows what the request returns (at least from postman): Content-Length: 126768 ----------------------------446648698401590502853205 Content-Disposition: form-data; name="select" Static Data ----------------------------446648698401590502853205 Content-Disposition: form-data; name="fileData"; filename="file.json" <file.json> ----------------------------446648698401590502853205 Content-Disposition: form-data; name="id" 1234567 ----------------------------446648698401590502853205-- HTTP/1.1 200 OK Date: Wed, 04 Dec 2024 18:55:06 GMT Content-Type: application/json; charset=utf-8 -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
I think this was not real, but part of the LSize isn't the right value because of a debugger issue. Wouldn't it be encrypted if I captured it with wireshark (https)? -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
Unfortunately not. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
I'm not making a lot of sense out of this windows function. Why would it return a size that doesn't include the terminating null \x00 character? When it returns the buffer, does it not null terminate the string? I'm not sure this is the issue as I modified the LSize to be 200 and let it make the second call and it still returned an empty string. edit: I'm back to why would WinHttpQueryHeaders return a proper 200 string that gets turned into an integer just fine, but not the OK part. Is there any way to access the actual response as bytes to see if it matches my postman test? -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
The original call to WinHttpQueryHeaders has a LSize==0, and it returns with ERROR_INSUFFICIENT_BUFFER. They intentionally call with a 0 to get the size. It skips by "if GetLastError <> ERROR_INSUFFICIENT_BUFFER then" and moves to SetLength, but now my LSize is 16579768, so clearly the debugger is back to not working right again. Moving to the CPU I can see that is loads EDX with a value 2 which is the size of OK. Then it does a SHR edx,1 and changes the value from 2 to 1. Then a DEC edx which changes it from 1 to 0. So the mystery here is WHY this line: SetLength(Result, LSize div SizeOf(Char) - 1); is dividing by sizeof(Char) which is apparently 2 and then subtracting 1. edit: looking at WinHttpQueryHeaders , it shows: [in, out] lpdwBufferLength Pointer to a value of type DWORD that specifies the length of the data buffer, in bytes Since it is dealing with wide strings, 2 could be a zero terminator for the wide string and it thinks there is nothing to return. Why would this function not see the "OK" in the http response? -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
It is 32 bit. Removing the two .pas modules and turning on debug dcu's fixes the issue with inspecting LSize. It gets cleared properly now and returning from WinHttpQueryHeaders leaves LSize at 0 which is why it isn't allocating it or retrieving it. The status line in the raw is: HTTP/1.1 200 OK If it makes any difference, I am sending multipart/form-data. -
TNetHTTPClient and StatusText not being "OK"
alank2 replied to alank2's topic in RTL and Delphi Object Pascal
I added the pas files to my project (C++) and stepped to ReadHeader - for some reason I can't evaluate variables properly - if I try to look at LSize even after stepping LSize:=0, it is NOT zero. After calling WinHttpQueryHeaders, it shows as zero. GetLastError is ERROR_INSUFFICIENT_BUFFER and it gets by that test. It does not get by the "if Length(Result) > 0 then " test however making me think that the SetLength() did not change the length? Oddly with the debugger on the "if Length(..." line it now shows the LSize as 274, but the if length test fails and it never calls WinHttpQueryHeaders the second time. -
I need to put a VCL form in a DLL and call it from another application. I've made the DLL and can call it just fine, but it shows as maximized even though it isn't supposed to be. //create form Form1=new TForm1(NULL); //show form modally Form1->ShowModal(); //copy result strcpy(APhoneNumber, Form1->phonenumber); //delete form delete Form1; Windows state is set to normal, If I put this in the formshow of the form: Form1->WindowState=wsNormal; There is no difference - I think the WindowState is already set this way. If I could click the title bar of the form, it does go to the right size. If I close it and reopen it with the above code (which creates a new TForm1), it does NOT happen a second time. If I change the formshow to this: Form1->WindowState=wsMinimized; Form1->WindowState=wsNormal; It does show as normal size the first and subsequent times, but I can see the animation of it minimizing and restoring. Why does this happen? Could it be perceiving the way the application that is using it was loaded such as maximized and overriding the WindowState somehow? if so, can that be prevented in a better way that what I'm doing? Other thoughts? edit: Does this have to do with Application->FInitialMainFormState? Can I change it somehow? When I try it says it is protected.
-
I get an error when I try to use a MP4 for the TMediaPlayer. Even the VideoPlayback sample will not work. I did try to play an AVI and it doesn't error, but it doesn't play correctly either with a lot of visual artifacts. Has anyone run into this before? I found this: https://stackoverflow.com/questions/64844414/register-new-media-codec-in-fmx-media-player-in-c-builder But when I try to #include <FMX.Media.Win.hpp>, I get a ton of errors: [bcc32c Error] Winapi.DirectShow9.hpp(237): use of undeclared identifier 'IDirectShowStream' [bcc32c Error] Winapi.DirectShow9.hpp(491): no member named 'PReferenceTime' in namespace 'Winapi::Dxtypes' ...
-
I've been using 10.3.3 for a long time, but needed to upgrade to a newer version because TMultipartFormData does not properly work on it. I get a 400 BadRequest instead of a 200 OK. Something with this component must have been updated because it works in later versions. I couldn't get 12.2 to install on the machine I have 10.3.3 because for some reason it won't install the bds.exe and then gives an error trying to run it (embarcadero unable to execute file c:\program files (x86)\embarcadero\studio\23.0\bin\bds.exe). Not getting past that I decide to install it on a different machine (win11 instead of win10) that I am moving to (new notebook). Install goes fine there, but it has a weird debugging crash problem I can't figure out: I am building a program in debug mode. It has one unit in it. I can step into the program. I can go to cursor and step through FormShow for Unit1. I can go to cursor and step through two different functions that are called by TStartTimer. BUT, if I go to cursor inside of even a mostly empty TStartTimer, it will hang for 60 seconds and the compiler/application will close and leave me looking at the desktop. Even if I cut this function down to this: void __fastcall TFMainform::TStartTimer(TObject *Sender) { // wchar_t ws1[4096]; wchar_t ws1[1024], ws2[1024], wts1[1024], cmd[1024]; //disable timer TStart->Enabled=false; } It will currently WORK in the above scenario. I can go to cursor the TStart->Enabled=false; statement and then step over/run and all is fine. If I change the variables so that the ws1 is unremarked and the line with the 4 variables below it is remarked, it will CRASH despite both still being the same amount of overall variables put on the stack. I've tried the classic win32 compiler and the newer one, same result. I've tried enabling or disabling codeguard, same result. The code works if I don't try to stop inside this function. If I unremark everything that was in there to make the API call, I get a 200 OK back from it. It just seems to hang if I try to stop and step inside it. edit to add; 11.3 does not have the problem. it works fine there. also, while I'm piling on 12.2, if I open the project and do a build immediately, I get errors like this: If I then double click unit1.cpp to open it and repeat the build, these errors go away. Any ideas?
-
I tried Application->Terminate(); or Svcmgr::Application->Terminate();, but they do not exist. There is this, but I have no idea what the CtrlCode is - is there one for "stop" ? void __stdcall ServiceController(unsigned CtrlCode) { Service1->Controller(CtrlCode); } What is the proper way for a service application to request shutdown? I have a ServiceExecute method being called that contains this: while (!Terminated) { ServiceThread->ProcessRequests(true); Sleep(250); } I can't change Terminated to true, it says it is inaccessible.
-
Can a windows service terminate/stop itself? If so, how?
alank2 replied to alank2's topic in General Help
Thanks Remy; I'll work through this! I appreciate it. -
Can a windows service terminate/stop itself? If so, how?
alank2 replied to alank2's topic in General Help
The sleep isn't really important as it was just added to keep it from consuming the CPU if ServiceThread->ProcessRequests(true); returns immediately. I am okay with ServiceThread->ProcessRequests(true); not returning until the service is stopped, the loop only needs to come into play during that situation where the "while (!Terminated || !TProcess->Enabled)" keeps it running until TProcess->Enabled becomes true (meaning that that method has successfully completed). The goal there is to not have the service stop without waiting for the TProcess method to complete. Maybe the 250ms should be dropped to 1ms in the Sleep as that could be keeping the ServiceThread->ProcessRequests(true); from executing more quickly to help it get stopped. So, my ServiceExecute does (1) init code, (2) ServiceThread->ProcessRequests until terminated and my tprocess timer method is complete, and finally (3) termination code. Is there a better way to do it? Should I move 1 into OnStart and 2 into OnStop? Can I eliminate ServiceExecute but still have it wait on the tprocess timer method to complete before executing OnStop and shutting down? -
Can a windows service terminate/stop itself? If so, how?
alank2 replied to alank2's topic in General Help
still editing -
Can a windows service terminate/stop itself? If so, how?
alank2 replied to alank2's topic in General Help
I called this from a timer method and it did not work. ServiceThread->Terminate(); But this worked beautifully. ServiceController(SERVICE_CONTROL_STOP); Thanks for the info! I've got other init code in it and my loop also tests to see if the timer has finished executing before exiting the loop. I clear TProcess->Enabled when entering it and set it when it exits. log1.Log(L"Service started"); TProcess->Enabled=true; while (!Terminated || !TProcess->Enabled) //do not quit if process is running until it is finished { ServiceThread->ProcessRequests(true); Sleep(250); } TProcess->Enabled=false; log1.Log(L"Service STOPPED");