Jump to content

aehimself

Members
  • Content Count

    1096
  • Joined

  • Last visited

  • Days Won

    24

Everything posted by aehimself

  1. aehimself

    How to open a file in the already running IDE?

    My code is your initial version, I'm not processing anything 🙂 msghwnd := AllocateHwnd(nil); Try atomservice := GlobalAddAtom(PChar(DDESERVICE)); atomtopic := GlobalAddAtom(PChar(DDETOPIC)); Try SendMessage(_ddehwnd, WM_DDE_INITIATE, msghwnd, Makelong(atomservice, atomtopic)); Finally GlobalDeleteAtom(atomservice); GlobalDeleteAtom(atomtopic); End; cmd := '[open("' + inFileName + '")]'; commandhandle := GlobalLockString(cmd, GMEM_DDESHARE); Try PostMessage(_ddehwnd, WM_DDE_EXECUTE, msghwnd, commandhandle); Finally GlobalUnlock(commandhandle); GlobalFree(commandhandle); End; Finally DeAllocateHwnd(msghwnd); End; Maybe I need to switch up that PostMessage to SendMessage. I'll give that modification a spin.
  2. aehimself

    How to open a file in the already running IDE?

    Hehe, you are right. Just this moment I entered a locked-up state again. 16394 until restarting the IDE. Starting the application from within our outside the IDE makes no difference. Double-clicking a file in explorer indeed does open the file in Delphi. It's strange but I THINK it started with the usual command-sending issue: WM_DDE_EXECUTE goes out but file is NOT opened in the IDE.
  3. aehimself

    How to open a file in the already running IDE?

    The window message version caused more havoc than it could solve. While collecting DDE targets worked more reliably, it interfered with sending commands. The finding no instances symptom was caused by the list connect, not Delphi's DDE server; adding error handling revealed that: convlist := DdeConnectList(ddeid, svchandle, topichandle, 0, nil); If convlist = 0 Then Raise EDelphiVersionException.Create('Retrieving the list of Delphi DDE servers failed, DDE error ' + DdeGetLastError(ddeid).ToString); threw DMLERR_NO_CONV_ESTABLISHED when something was "locked up". I'm now playing around with res := DdeInitializeW(ddeid, nil, APPCMD_CLIENTONLY, 0); Seems to be stable so far.
  4. aehimself

    How to open a file in the already running IDE?

    This idea won't work as intended, as you are sending all the messages to all TPUtilWindows of all instances you'll find. At least for my purpose, where I am separating Delphi IDE instances by versions. The theory is interesting though. You think one Delphi instance can have more DDE servers, which are constantly being destroyed / created?
  5. aehimself

    How to open a file in the already running IDE?

    And with this, you made all calls work fine from a background thread!
  6. aehimself

    How to open a file in the already running IDE?

    I'm using the code to start an IDE if nothing was detected and open a file in it. Once the first instance can not even be detected anymore I still can control the second just fine. This makes me believe the issue is with the DDE server of a specific instance. There are two options. Either we lock up Delphi's DDE server with our code, or Delphi's DDE server is buggy and crashes by itself. Once an instance locks up I'll see if I can double-click on a file in Explorer to open it.
  7. aehimself

    How to open a file in the already running IDE?

    Btw, stability issue seem to be solved by calling DdeDisconnectList when finished. I'll push an update soon.
  8. aehimself

    How to open a file in the already running IDE?

    I took the liberty to include everything in a small, easy to use package: https://github.com/aehimself/AEFramework/blob/master/AE.DelphiVersions.pas Usage: Var dv: TDelphiVersions; v: TDelphiVersion; begin dv := TDelphiVersions.Create; Try For v In dv.InstalledVersions Do If v.IsRunning Then v.OpenFile('C:\a.pas'); Finally FreeAndNil(dv); End; End; Multiple DDE queries clearly lock something up, I suspect calling .IsRunning in an infinite loop will turn from True to False after a while. Also, OpenFile will raise an AV if there are no instances. I'll add some error handling later.
  9. aehimself

    How to open a file in the already running IDE?

    Had that in mind but I'm afraid of using version numbers, as you have to consider patch levels in each version. I guess it might change bds.exe version number too.
  10. aehimself

    How to open a file in the already running IDE?

    Yep, similar to my approach. I moved this to a separate function though, but logic is the same.
  11. aehimself

    How to open a file in the already running IDE?

    Happened to me too, however a simple Delphi restart solved it. Maybe DDE server died in Delphi, as DdeQueryNextServer found no matches. Anyway, I added some information gathering and now I have the full process name of each process which was found. From here, I only need to enumerate the bds paths in Registry to find which Delphi version that executable is for. Little bit more code than I expected, but at least it works! Thank you!
  12. aehimself

    How to open a file in the already running IDE?

    Perfection, works like a charm. It triggered my antivirus though, hope won't happen in the real application 🙂
  13. aehimself

    How to open a file in the already running IDE?

    How...?! It's the same garbage here, only it appears in the IDE. I thought autoconnecting makes a difference, but that doesn't seem to be the case... I did not find the needed WinApi calls yet. I might look into it, seems something is broken in TDDEClientConv between XE4 and 11.2...
  14. aehimself

    How to open a file in the already running IDE?

    I remember seeing it on a really old newslist that TDDEClientConv heavily suffers from bad coding and I tend to believe something is not right with it in this case. I already tried with simple casting, StrPCopy, sending @PAnsiString[1] instead of PAnsiChar, even like this: Var pac: PAnsiChar; s: String; tb: TBytes; len: Integer; begin s := '[open("' + Edit1.Text + '")]'; tb := TEncoding.Default.GetBytes(s); len := Length(tb); GetMem(pac, len + 1); ZeroMemory(pac, len + 1); Move(tb[0], pac^, len); ... but BDSLauncher always replies with some Chinese characters what it tried to execute as a command. I can not get more PAnsiChar than this. I'll try to find a different component to check.
  15. aehimself

    How to open a file in the already running IDE?

    Strange to me too, but yes, I am:
  16. aehimself

    How to open a file in the already running IDE?

    When stepping in .ExecuteMacro, a message box actually pops up but disappears right after the line hdata := DdeClientTransaction(Pointer(hszCmd), DWORD(-1), FConv, 0, FDdeFmt, XTYP_EXECUTE, TIMEOUT_ASYNC, @ddeRslt); What it said: So I guess the command is incorrect, Delphi really didn't like the casting. Now attempting to properly build my command, because with Var pac: PAnsiChar; s: AnsiString; begin s := '[open("' + Edit1.Text + '")]'; pac := PAnsiChar(s); If Not DDEClientConv1.ExecuteMacro(pac, False) Then Begin my result is: 🙂
  17. aehimself

    How to open a file in the already running IDE?

    Getting close 🙂 Never worked with DDE so it'll take some attempts to succeed I believe. So far I have the following code: Memo1.Lines.Add(sLineBreak + '----------------------------------------'); Memo1.Lines.Add('Opening ' + Edit1.Text); // DDEClientConv1.ServiceApplication := '"C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\bdsLauncher.exe" "C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\bds.exe" /np'; DDEClientConv1.ServiceApplication := 'C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\bdsLauncher.exe'; Memo1.Lines.Add('Setting DDE link...'); If Not DDEClientConv1.SetLink('bdsLauncher', 'system') Then Begin Memo1.Lines.Add('Setting link failed!'); Exit; End; Memo1.Lines.Add('Opening DDE link...'); If Not DDEClientConv1.OpenLink Then Begin Memo1.Lines.Add('Opening link failed!'); Exit; End; Try Memo1.Lines.Add('Invoking DDE command...'); If Not DDEClientConv1.ExecuteMacro(PAnsiChar('[open("' + Edit1.Text + '")]'), False) Then Begin Memo1.Lines.Add('Invoking command failed!'); Exit; End; Finally Memo1.Lines.Add('Closing DDE link...'); DDEClientConv1.CloseLink; End; No errors are shown but nothing gets executed and I get a ding sound. No popups, no entries in the event log. Anyone has experience debugging DDE, where should I look for errors? I took all the keywords from the registry, HKCU\BDE.pas. ServiceApplication came from Command\Default, SetLink parameters from ddeexec\application\Default and ddeexec\topic\Default, the macro from ddeexec\default.
  18. aehimself

    How to open a file in the already running IDE?

    My guess was on some tricky Windows messages, but DDE is a valid option as well. As I have no source for BDSLauncher I can not say. I took a peek at @dummzeuch's dzBdsLauncher but that also is executing a direct bds.exe call, probably resulting in a new IDE. Finding the method and replicating it would be the goal of this topic.
  19. aehimself

    How to open a file in the already running IDE?

    I do believe that's more than enough, please try not to steer the conversation away. Can we get back to the topic, please?
  20. aehimself

    How to open a file in the already running IDE?

    No, it does not 🙂 First, CurrentKey has a zero value after .OpenKeyReadOnly. Second, you are assigning a wrong registry path, not what the API expects: https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shellexecuteinfoa hkeyClass Type: HKEY A handle to the registry key for the file type. The access rights for this registry key should be set to KEY_READ. This member is ignored if fMask does not include SEE_MASK_CLASSKEY. Edit: wrong parameter copied
  21. aehimself

    How to open a file in the already running IDE?

    That is really surprising as that's not how you open a registry key with TRegistry AND even if you correct that, reg.CurrentKey won't be changed after a single .OpenReadOnly. Running the code on a PC with Delphi 10.4 and 11 installed also confirms failure: it opens up the file in Delphi 10.4.
  22. aehimself

    How to open a file in the already running IDE?

    Tried. Bds.exe never starts, bdslauncher.exe never quits, just hangs. No windows, no errors, nothing. Also tried adding the necessary (?) -pDelphi switch, same result. Tried giving these parameters only to Bdslauncher and only the source file. No effect.
  23. aehimself

    How to open a file in the already running IDE?

    This is exactly what I did. This introduces the new instance issue, which this topic is about. I'm probably missing a parameter - I just don't know which.
  24. aehimself

    How to open a file in the already running IDE?

    Please read the question again. To be able to launch with a specific Delphi version you need to start bds.exe, not just the .pas file; this is how it was until now.
  25. aehimself

    Active Directory authentication

    Var TokenHandle: THandle; Begin If LogonUser(PChar(UserEdit.Text), PChar(DomainEdit.Text), PChar(PasswordEdit.Text), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, TokenHandle) Then Try // Credentials are valid... // In case needed: If ImpersonateLoggedOnUser(TokenHandle) Then Try // Do stuff in the context of user Finally RevertToSelf; End; Finally CloseHandle(TokenHandle); End; End; User must have network login right to the PC, though.
×