Author Topic: Environment goes away when dropping a file on a WPProgram object  (Read 3148 times)

Doug Clark

  • Sr. Member
  • ****
  • Posts: 368
  • Karma: +12/-1
    • View Profile
It appears to me that an empty environment is passed to the program started when a file is dropped on a WPS program object.

Double clicking the WPProgram object doesn't do this, and double-clicking on a file associated with the program object also doesn't do this. - meaning the full environment is passed in both situations.   It appears to happen only when dropping a file on an WPProgram object.

Has anyone else experienced this issue?  Meaning is this a bug, or is there a reason for this that I am unaware of?

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1440
  • Karma: +28/-0
    • View Profile
Re: Environment goes away when dropping a file on a WPProgram object
« Reply #1 on: June 05, 2025, 02:13:31 am »
hey Doug!

It appears to me that an empty environment is passed to the program started when a file is dropped on a WPS program object....

Ugh???  :o

...It appears to happen only when dropping a file on an WPProgram object.

Has anyone else experienced this issue?  Meaning is this a bug, or is there a reason for this that I am unaware of?

Are we talking here ONLY the matching file-type and associated program object, or everything?

I tested a simple TXT file stored on my Desktop, it worked correctly dropping that file on both the WarpCenter as well as actual WPS program icons (tried with multiple text editors).

Rich Walsh

  • Sr. Member
  • ****
  • Posts: 406
  • Karma: +30/-0
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: Environment goes away when dropping a file on a WPProgram object
« Reply #2 on: June 05, 2025, 05:18:34 am »
It appears to me that an empty environment is passed to the program started when a file is dropped on a WPS program object.

I'm afraid you've found The Bug in DTProgram. I know what the issue is, I'm just not sure how to resolve it. The quick fix is to remove any entries you made on the 'Environment' tab of the program object's notebook.

When you drop a datafile on a program object, the pgm object does *not* open the file. Instead, the datafiles's wpDroppedOnObject() method is called, advising that it was just dropped on the pgm object. The datafile then queries the pgm object for its PROGDETAILS structure which contains the particulars for that program. Using this info, the datafile runs the program itself. And here lies the problem...

PROGDETAILS includes contains an optional 'pszEnvironment' field that can be used to supplement or replace the default environment When DTProgram sees the field contains something, it merges whatever it finds with the existing environment. Unfortunately, WPProgram assumes that the field contains the entire environment, leaving whatever it starts with nothing but your few entries.

The obvious solution is to always merge your entries with the generic environment, but that entails a lot of overhead to resolve a problem that seldom occurs. I'll see what I can do.

Doug Clark

  • Sr. Member
  • ****
  • Posts: 368
  • Karma: +12/-1
    • View Profile
Re: Environment goes away when dropping a file on a WPProgram object
« Reply #3 on: June 05, 2025, 08:10:17 am »
Rich,

Quote
When you drop a datafile on a program object, the pgm object does *not* open the file. Instead, the datafiles's wpDroppedOnObject() method is called, advising that it was just dropped on the pgm object. The datafile then queries the pgm object for its PROGDETAILS structure which contains the particulars for that program. Using this info, the datafile runs the program itself. And here lies the problem...

Thanks for that explanation.  I knew that wpOpen() in the program object wasn't getting called when a file was dropped, but I didn't know what was getting called and how the program was executed .  Is wpOpen() called in the datafile object when it is double-clicked and it then runs the program by querying PROGDETAILS the same way?

I am afraid that I probably am causing the problem because I am overriding wpQueryProgDetails() in the program object and modifying the contents of PROGDETAILS - which it appears that DTProgram is picking up on a drag/drop and hence the issue.

I could add the "standard" environment  to PROGDETAILS since I am modifying some of the contents anyway.  And that may be the best solution.  But I am a little worried about a memory overrun.  Most of the time when wpQueryProgDetails() is called it is called twice: the first time with a NULL pointer for returning the contents of the PROGDETAILS in order to get the needed size for allocating the memory to hold the PROGDETAILS and the second time with a pointer to the memory allocated to hold the PROGDETAILS with the pointer hopefully the correct size.  But I have noticed that sometimes it is only called once, with an "assumed large enough" size allocated for holding PROGDETAILS,  (If I am remembering correctly the size I saw was 1024)   If I add in the standard environment it could exceed that "assumed large enough" size.

I saw that "only call once with an assumed large enough size" behavior on a machine that was running eWorkplace, but I don't know if that is a eWorkplace particular behavior or something else that was installed on that machine that was calling  wpQueryProgDetails().

Thanks for the help.