Author Topic: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR  (Read 1515 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« on: June 15, 2019, 10:25:10 PM »
 Sorry I didnt know what title to set. Basically when i compile an executable in Oxygen and execute it from my IDE
everything works as expected. I can re-invoke it as many times as i want and re-compile in any way.

 But when i compile a dll, and invoke a tester app, it executes fine, 1 or two times. Afterwards, CreateProcess() always
returns 0 and the PROCESS_INFORMATION header's member: hProcess always comes empty.

 Maybe something is not freeing correctly after execution?

 This is happening with headers intact, no modifications from me. Can you give it a try Charles? Attached are the DLL and EXE
im executing. I can re-invoke them as many times as i want from the windows explorer, but when invoking them
programmatically with CreateProcess(), something is not right. Im using this for invoking the executable:

Code: [Select]
   Result = CreateProcess(ByCopy executable, _
                          ByCopy commandline, _
                          SecAttrib, _
                          SecAttrib, _
                          %True, _
                          %NORMAL_PRIORITY_CLASS, _
                          ByVal StrPtr(EnvData), _
                          ByVal VarPtr(PathToCGI), _
                          StartInfo, _
                          ProcInfo)

 This works fine for any other executables (oxygen or PowerBASIC), except for oxygen executables that require a DLL, which fails after second or third attempt, or worse... crashes the whole IDE with a runtime error at user32.dll.


Brian Alvarez

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #1 on: June 15, 2019, 10:32:10 PM »
 :(

Charles Pegge

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #2 on: June 16, 2019, 02:07:59 AM »
Using t.exe which uses your example dll, It works in this test rig:

Code: [Select]
'10:47 16/06/2019
'Test repeated CreateProcess
uses corewin


'  type STARTUPINFO
'  dword  cb
'  char*  lpReserved
'  char*  lpDesktop
'  char*  lpTitle
'  dword  dwX
'  dword  dwY
'  dword  dwXSize
'  dword  dwYSize
'  dword  dwXCountChars
'  dword  dwYCountChars
'  dword  dwFillAttribute
'  dword  dwFlags
'  word   wShowWindow
'  word   cbReserved2
'  byte*  lpReserved2
'  sys    hStdInput
'  sys    hStdOutput
'  sys    hStdError
'  end type


  function Exec(string c, sys wait=0)
  ===================================
  STARTUPINFO infs
  PROCESS_INFORMATION infp
  CreateProcess 0,c,0,0,0,0,0,0,@infs,@infp
  if wait
    WaitForMultipleObjects 1,@infp.hthread,1,-1
  end if
  CloseHandle infp.hProcess
  CloseHandle infp.hThread
  end function

  int i
  int wait=1
  for i=1 to 8
    Exec "t.exe"  ',wait
  next
  print "done"

Code: [Select]
/*
'03:31 16/06/2019
'check dlls
$dll
$filename "t.dll"
uses rtl32

extern
FUNCTION DLLFUNC() AS string, export

    RETURN "Hello world, from an exported DLL function."

END FUNCTION
end extern
*/

/*
'03:32 16/06/2019
$filename "t.exe"
uses rtl32

DECLARE FUNCTION DLLFUNC LIB "t.dll" ALIAS "DLLFUNC" () AS STRING

FUNCTION PBMAIN() AS INT
   print DLLFUNC()
END FUNCTION

PBMAIN() ' invoke entry point
*/

Brian Alvarez

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #3 on: June 16, 2019, 01:30:43 PM »
I think i discovered something.

 I was just able to call oxygen + its dll many times in a row from my IDE. I suspect the issue happens when an oxygen executable is invoked with a non matching dll.

 Strangely, when a powerBASIC executable cannot be instantiated, the issue doesnt happen, only when an oxygen executable cannot start. I Think create process cannot free something up.

« Last Edit: June 16, 2019, 02:06:04 PM by Brian Alvarez »

Brian Alvarez

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #4 on: June 16, 2019, 04:34:13 PM »
 The attached example, can call a 32bit exe and 32bit DLL as many times as i want with no errors.

 But can call only a few times a 32bit exe + a 64bit dll (doesnt open). Afterwards, an error is displayed
even for 32bit exe and 32bit dll.

 


Charles Pegge

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #5 on: June 16, 2019, 07:16:13 PM »
I would never attempt to load a 64bit dll into a 32bit process or vice-versa.

Could you post a ZIP file instead of the RAR. My 7-ZIP can't read it.

Brian Alvarez

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #6 on: June 16, 2019, 08:48:12 PM »
Normally, i never would either. But during development all sorts of mixtures can happen and
i would like my IDE to handle such confusions a little bit more gracefully than crashing.  ;D

 Here is a zip. Thanks for looking into it Charles.

Brian Alvarez

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #7 on: June 16, 2019, 09:46:04 PM »
Hello Charles,

 Increasing the stack fixed this in a satisfactory manner. I dont think there is a need to struggle
with this anymore. I haven't had any crashes since i increased the stack space.

 However, i still tend to think it would be confusing if someone mixes modules by accident and all
they get at execution is a messagebox with the name of the dll. Specially if the header says O2H.

 They would not get any clues as to what error happened, and i wouldnt have any clue about the
application not firing correctly and i could not offer any hints.

 There is no need to have a custom error handling for every single declaration. I understand there
can be hundreds and this can bloat the executable. But there can be a centralized error handler
that loads the code. There would only be one handler for all the declarations, instead of one handler
per declaration. I dont know if i made sense in my explanation.
« Last Edit: June 16, 2019, 09:55:42 PM by Brian Alvarez »

Arnold

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #8 on: June 16, 2019, 10:41:29 PM »
If I call this correctly, the error could be a wrong/missing dll name or a wrong/missing function name in a dll. Maybe it would be sufficient to add something like "Wrong/Missing: <Name>"?

Brian Alvarez

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #9 on: June 16, 2019, 11:03:16 PM »
 I think you are correct Arnold. The problem is that every executable could load
hundreds or even thousands of functions. Charles wants to avoid bloating the
executables.

 Im sure there must be a reasonable way to do so without creating an extremely big file.

Brian Alvarez

  • Guest
Re: Exe + CreateProcess = OK, Exe + DLL + CreateProcess = ERR
« Reply #10 on: June 16, 2019, 11:14:16 PM »
I once did that generating 32 bit executables, but it was a long time ago.