Jump to content

Mark Williams

Members
  • Content Count

    272
  • Joined

  • Last visited

Everything posted by Mark Williams

  1. Mark Williams

    SendMessage From DLL

    BTW should have noted there was no need for ChangeWindowMessageFilterEx, but good to know about it.
  2. Mark Williams

    SendMessage From DLL

    Ah ha! The penny at last drops. The dangers of copying code that works in 32 bit, but no longer in 64 bit. My DLL is 64bit, but when I created a test executable to try and send the message I must have compiled it as 32 bit rather than 64 so it worked. The SendMessage needed to be: WinAPI.Windows.SendMessage(Hdl, WM_COPYDATA, 0, LPARAM(@copyDataStruct)); That was the only reason the message was not getting through and had I realised this 48 hours ago I might have some hair left. It's time for that Lockdown drink! I will raise a glass to you
  3. Mark Williams

    SendMessage From DLL

    It might be a UIPI issues as flagged by @David Heffernan initially and missed by me! But I don't think so. However not dealt with UIPI issues before so I may be handling it incorrectly, Whilst Word runs at a low level I think the DLL Add-In will be at the same level as my receiving app. Also, as you pointed out if there is an UIPI error then GetLastError is set to 5. My SendMessage is reporting success. However I have tried to incorporate ChangeWindowFilterEx within my receiving app to see if that makes any difference. type TChangeFilterStruct = packed record cbSize: DWORD; ExtStatus: DWORD; end; PChangeFilterStruct = ^TChangeFilterStruct; function ChangeWindowMessageFilterEx(hWnd: HWND; Message: UINT; Action: DWORD; ChangeFilterStruct: PChangeFilterStruct): Bool; stdcall; external 'user32.dll'; const MSGFLT_ALLOW = 1; MSGFLT_DISALLOW = 2; MSGFLT_RESET = 0; {In formcreate:} ChangeWindowMessageFilterEx(Handle, WM_COPYDATA, MSGFLT_ALLOW, nil); If I am implementing this correctly there doesn't appear to be a UIPI error.
  4. Mark Williams

    SendMessage From DLL

    Word ID is a randomly generated integer value. It's not intended to be used as a handle. Just a way of identifying which Word window my app is communicating with. My app passes its own handle to be stored in the word document as follows: Within a word document the variables are stored as a wideString. To get the handle of my app from within the DLL I call this function which queries the Add In's host word window: Result:=0; val := Doc.Variables.Item(i).Value; tryStrToInt(val, hdl); Result := Hdl; Result is a THandle. Debugging a 64 bit AddIn is a bit problematic. So I have not looked into it yet. However, I have written to a log file to output what is happening at the various stages. I know that the hdl being passed to SendMessage is the correct hdl of my app. Also GetLastError returns success after SendMessage (if that means anything!) On My app I show the value of its handle on a label when it is running. Let's say its 12345678. If I create another Delphi executable and call WinAPI.Windows.SendMessage(12345678, WM_COPYDATA, 0, Integer(@copyDataStruct)); That works as expected. If I do the same in my Add In DLL (ie substitute the hdl var with the Longint value of my app's handle) it doesn't work.
  5. Mark Williams

    FTPServer Beginner

    I am looking for some general guidance on how to go about setting up an FTP server for the first time. I have opted for TIDFTPServer for this purpose and have been through the help files and searched Google, but I have come up with very limited information. I don't want to launch into this in my usual bull in a china shop manner only to find later that I have gone about it in the least appropriate way. So apologies in advance for the broad nature of this topic. In essence my requirements are for a basic FTP Server. However, I want to try and strictly control what users can upload and, in particular, download. My fledgling thoughts: Uploads The user requests permission for upload via my webserver and if authenticated is issued with a unique token to be stored in the database along with an expiry time which the user will need to renew periodically via the webserver and an identifier to identify which folder(s) the user is allowed to upload to. The FTP client would submit the token to the FTP server which would retrieve the token, expiry time and folder identity prior to permitting any upload request. When the client has finished it will request the deletion of the token. There are likely often to be large numbers of files to be uploaded so preferably the FTP Server will be able to store the token, expiry time etc rather than querying the database for every upload. The FTP client would submit the token on every upload request. The FTP Server would check periodically whether the token has been removed. Downloads There may be a requirement for download of a large batch of files. So similar approach to the above. I already keep a record of every file in a database so each has a unique id and there is another table which records user rights to access a given file. Before submitting download request user applies for token via webserver and at the same time submits a list of ids of those file he intends to download. Webserver checks which ones user has access to and populates a table with the file ids ("permitted_files"). On receiving the retrieve request the FTP does the same as for upload, but additionally queries the "permitted_files" table to see which files the user is permitted to download. Questions Is this broadly a sensible approach? If not, how better to go about this? Assuming it is sensible, what do I need to implement this within the FTPServer component. My best guess at the moment is that it would be handled via CommandHandlers. No GUI interface is required and I don't really need a command line so how best to implement this on the Server: as a Windows service? As the FTP Server may be receiving numerous requests at the same time how best to manage the data relative to specific requests (ie tokens, permitted file ids etc).
  6. Mark Williams

    FTPServer Beginner

    Thanks to everyone for the detailed responses and suggestions. I think my fundamental error was my assumption (long-held and it seems with little basis) that FTP is faster than HTTP for multiple file transfers. I have already written an ISAPI dll using Delphi's TWebBroker which seems to be working well for my needs I just thought I could speed things up with FTP. From the above responses a better approach may be to more finely tune my ISAPI dll. The comments re Real Thin Client are noted and I will certainly look into this at a later point. In short, thanks for the feedback which it appears has saved me a potential mountain of unncessary work!
  7. Mark Williams

    Problem starting FTP Server

    I am trying to create a FTP server for the first time using TIDFTPServer. I have dropped a TFTPServer onto a form and changed properties only as follows: Active = True Bindings = < item IP = '**.**.***.***' Port = 21 end> ReuseSocket = rsTrue If I set the IP address as the external ip address for the server I get an EIDCouldNotBindSocket error and it advises that "Address and port are already in use" when I try to start it. I don't get this problem if I change the IP address to the server's local address (192.168.0.12). Should the IP address always be set to the local IP? I've noticed that IDFTP has an ExternalP property and also ServerHOST property. There is help on the ExternalIP property, but no on the ServerHOST property. Would I be right in assuming these properties are used for external connections to the FTP server rather than anything in the FTPServer's settings? With respect to the ExternalIP address this also seems to require setting of the DataPort. I have tried connecting setting ExternalIP to the relevant IP address and DataPort to 21. Host is blank. When I try to connect I get an error message telling me a Host is required. I've tried setting Host to the external IP and also ServerHost, but either I get Host required error or time out.
  8. Mark Williams

    TButtonedEdit Styles and transparency

    When using a dark theme with TButtonedEdit and an imagelist with DrawingStyle set to dsTransparent, the image always shows with a white background. That's obviously fine when the edit box is white, but not when it is dark. My images in the imagelist have a background colour of clFuschia. For some reason I can't change the transparent color in the imageList's editor. It is disabled and clDefault is selected. So I tried another approach, creating an imageList at runtime and adding masked images to it as follows: Function GetTransparentImageList(Owner:TComponent; SourceImages:TImageList; BMPIndex:Integer):TImageList; var bmp:TBitmap; begin bmp:=TBitmap.Create; try if SourceImages.GetBitmap(BMPIndex, bmp) then begin Result:=TImageList.Create(Owner); With Result do begin DrawingStyle:=dsTransparent; //tried with and without for all three color options below AddMasked(bmp, clNone); //tried with clFuchsia and clDefault end; end; finally bmp.Free; end; end; Still the TButtonedEdit stubbornly shows the button image with a white background. Am I missing something?
  9. Mark Williams

    TEncryptedZipFile

    @Uwe Raabe I have just had a look at this component on your blog. I could get it to write an encrypted zip file, which I can open manually no problem, but I cannot get it to decrypt using the component. I downloaded the amended unit from https://www.uweraabe.de/Blog/2017/05/07/tzipfile-with-password-encryption-part-3/, but this still didn't work for me. My code for unzipping is as follows: Zipper:=TEncryptedZipFile.Create('Mark'); Stream:=TMemoryStream.create; try DecompressionStream:=TStream.Create; Zipper.Open(OpenDialog1.filename, zmReadWrite); Zipper.Read('File', DecompressionStream, zh); Stream.CopyFrom(DecompressionStream, DecompressionStream.size); {Crashes here} DecompressionStream.Free; Stream.Position:=0; Stream.SaveToFile(ExtractFilePath(includeTrailingPathDelimiter(openDialog1.FileName))+'File.docx'); Zipper.Close; finally zipper.Free; stream.Free; end; I have used the same routine as I would for reading from the standard TZipFile ie using the DecompressionStream. Can't work out whether my approach is write or if there is a problem with the TEncryptedZipFile code. Anyways my debug output is: System.Classes TStream.ReadBuffer System.Classes 8340 +1 TStream.ReadBuffer uEncryptedZipFile 299 +9 TDecryptStream.Skip uEncryptedZipFile 277 +10 TDecryptStream.Seek System.Classes 7561 +1 TStream.SetPosition System.ZLib 2891 +32 TZDecompressionStream.Read System.ZLib 2939 +27 TZDecompressionStream.Seek System.Classes 7569 +2 TStream.GetSize
  10. Mark Williams

    FTP add virtual directory

    Using IIS. New to FTP. Can anyone please give me a steer as to how to programmatically add and configure virtual FTP directories in IIS via Delphi?
  11. Mark Williams

    FTP add virtual directory

    @Remy LebeauThanks for the detailed response. Are there any problems running an Indy FTP server alongside IIS? Also, do you know of any good sample FTP server projects anywhere?
  12. Mark Williams

    ShellExecute and passing of password

    I would like to shellexecute one app from another. Both apps require username and password. I would like to be able to pass the password securely from one app to the other. Obviously, command-line parameters are out and I would imaging a memory mapped file will also not be secure. Is there any relatively simple and secure way of achieving this.
  13. Mark Williams

    FTP add virtual directory

    Is it not possible to also password protect the folder? My intention is to maintain a record of the virtual folders in a database and require the user to signal continued use of the folder and as soon as there is a failure to do so the folder would be deleted. Is this the Overbyte stuff? I will have a look. So if I wanted to run IIS and ICS on the same server I would need a second static ip?
  14. Mark Williams

    FTP add virtual directory

    Thanks. I'll have a look at WMI. Which type library do you use? I've got a couple on my registered libraries.
  15. Mark Williams

    FTP add virtual directory

    Yes it's pretty easy to set up via IIS, but the security angle is precisely why I don't wish to do it this way. I want to check the user's credentials against database and then issue that user a one-off password for a single transaction and add a temporary ftp folder, which then gets removed as soon as the user has completed the transaction. There may be better ways of doing this. As I said I'm a FTP novice!
  16. Mark Williams

    ISAPI DLL MaxConnections

    The default MaxConnections is set at 32 for TISAPIApplication. I have no idea how many people may be calling my dll at any given time. 32 seems to me to be too low a number. I have set it to 200. I cannot find any advice as to best policy on setting this value. The help file simply says to test the ActiveCount and InactiveCount and adjust accordingly. That is going to be a little difficult to test. I don't want to have exceptions flying off because of MaxConnection exceeded and likewise I don't want to degrade performance. If, for example, I set MaxConnection to 1000 I assume that will not of itself degrade performance and that there will only be issues when actual connections are that high, If that is right then it seems to me that slightly deteriorated performance is preferable to exceptions due to exceeding max connections. Or am I missing something?
  17. Mark Williams

    ISAPI DLL MaxConnections

    Thanks. I'll look into this at some point. However, my ISAPI dll isn't really designed to do heavy lifting. Just user validation, configuration settings and downloading of smallish files. There is occasionally a need to upload/download largish files and this is something I am planning to move to FTP or maybe there is a better/faster solution?
  18. I wouldn't have thought it was possible to do this, but when my kids sign in to my Netflix account from various locations I get an email from Netflix to let me know what country and region they have signed in from. Does anyone have any idea how Netflix gets this info?
  19. Mark Williams

    Detect user location from ip address

    Must be a European thing. As of last Friday it is now unlawful for me to get such jokes!
  20. Mark Williams

    Detect user location from ip address

    I'm not sure what you're referring to. Can't see anything on the page/website which helps.
  21. Mark Williams

    Detect user location from ip address

    I found an example of how to do it (although not tried it) here: https://www.example-code.com/delphiDll/geolocation_ip_address.asp
  22. Mark Williams

    ISAPI DLL MaxConnections

    I'll give that a try and see how it pans out. I thought this was more or less what iis does with the dll.
  23. Modern scanners on auto color detection mode seem to be very efficient in detecting whether a document is a text document and whether to scan it as monochrome even though the image contains some degree of color. It has to be more than a pixel by pixel analysis to analyse the extent of the color in any image. Does anyone have any idea how this is done or even better if they can point me o some example code? I have searched on Google and the only example I can find is written in Python and I have no idea how to adapt for Delphi (Python example).
  24. Ok. Thanks. I'll have a look at that and report back if I can improve on what I have already got.
  25. Scanlines is fast enough for my purposes even when it scans every pixel. I would be reluctant to rely on random sampling.
×