Calling 32-bit CreateFile in a 16-bit program

Hi all !

I'm trying to call the CreateFile function of kernel32.dll from a 16-bit program (written in BPW 7.0), using the [b]thunk functions[/b] of the 16-bit kernel (LoadLibraryEx32W, FreeLibrary32W, GetProcAddress32W, GetVDMPointer32W and CallProc32W).

Under Windows NT 4.0 (SP6) and Windows 2000 Pro (SP4) I get an access violation error in NTDLL.DLL.

I've verified all the parameters and I've converted all 16:16 pointers to linear addresses : it still doesn't work.
It's the first time I get an error with the thunk functions.

Could someone explain me what's wrong ?

Comments

  • : Hi all !
    :
    : I'm trying to call the CreateFile function of kernel32.dll from a 16-bit program (written in BPW 7.0), using the [b]thunk functions[/b] of the 16-bit kernel (LoadLibraryEx32W, FreeLibrary32W, GetProcAddress32W, GetVDMPointer32W and CallProc32W).
    :
    : Under Windows NT 4.0 (SP6) and Windows 2000 Pro (SP4) I get an access violation error in NTDLL.DLL.
    :
    : I've verified all the parameters and I've converted all 16:16 pointers to linear addresses : it still doesn't work.
    : It's the first time I get an error with the thunk functions.
    :
    : Could someone explain me what's wrong ?
    :
    :
    Could you show some of the code, like parameter conversions?



  • : : Hi all !
    : :
    : : I'm trying to call the CreateFile function of kernel32.dll from a 16-bit program (written in BPW 7.0), using the [b]thunk functions[/b] of the 16-bit kernel (LoadLibraryEx32W, FreeLibrary32W, GetProcAddress32W, GetVDMPointer32W and CallProc32W).
    : :
    : : Under Windows NT 4.0 (SP6) and Windows 2000 Pro (SP4) I get an access violation error in NTDLL.DLL.
    : :
    : : I've verified all the parameters and I've converted all 16:16 pointers to linear addresses : it still doesn't work.
    : : It's the first time I get an error with the thunk functions.
    : :
    : : Could someone explain me what's wrong ?
    : :
    : :
    : Could you show some of the code, like parameter conversions?
    :
    :
    :
    :
    Thank you for your answer !

    You may find excerpts of the thunking unit on
    http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/win32_e.pas
    (see then WIN32_CREATEFILE or WIN32_OPENFILE function)

    and the calling program on
    http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/essai_e.pas
  • [b][red]This message was edited by Masterijn at 2004-6-18 4:14:47[/red][/b][hr]
    : : : Hi all !
    : : :
    : : : I'm trying to call the CreateFile function of kernel32.dll from a 16-bit program (written in BPW 7.0), using the [b]thunk functions[/b] of the 16-bit kernel (LoadLibraryEx32W, FreeLibrary32W, GetProcAddress32W, GetVDMPointer32W and CallProc32W).
    : : :
    : : : Under Windows NT 4.0 (SP6) and Windows 2000 Pro (SP4) I get an access violation error in NTDLL.DLL.
    : : :
    : : : I've verified all the parameters and I've converted all 16:16 pointers to linear addresses : it still doesn't work.
    : : : It's the first time I get an error with the thunk functions.
    : : :
    : : : Could someone explain me what's wrong ?
    : : :
    : : :
    : : Could you show some of the code, like parameter conversions?
    : :
    : :
    : :
    : :
    : Thank you for your answer !
    :
    : You may find excerpts of the thunking unit on
    : http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/win32_e.pas
    : (see then WIN32_CREATEFILE or WIN32_OPENFILE function)
    :
    : and the calling program on
    : http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/essai_e.pas
    :
    Hai, I took a good look at it, and can't see anything wrong.

    My suggestion is to test it with a nil pointer as file name. If this returns a error, but no access violation then this parameter is the problem. Otherwise its probably in the WIN32 unit.
    Also can you post the exact error text? (I don't have BP7 running anymore, so I can't do the testing myself. B.t.w. why don't you use Delphi for win32 programming?)






  • [b][red]This message was edited by Alcatiz at 2004-6-20 22:39:11[/red][/b][hr]
    : [b][red]This message was edited by Masterijn at 2004-6-18 4:14:47[/red][/b][hr]
    : : : : Hi all !
    : : : :
    : : : : I'm trying to call the CreateFile function of kernel32.dll from a 16-bit program (written in BPW 7.0), using the [b]thunk functions[/b] of the 16-bit kernel (LoadLibraryEx32W, FreeLibrary32W, GetProcAddress32W, GetVDMPointer32W and CallProc32W).
    : : : :
    : : : : Under Windows NT 4.0 (SP6) and Windows 2000 Pro (SP4) I get an access violation error in NTDLL.DLL.
    : : : :
    : : : : I've verified all the parameters and I've converted all 16:16 pointers to linear addresses : it still doesn't work.
    : : : : It's the first time I get an error with the thunk functions.
    : : : :
    : : : : Could someone explain me what's wrong ?
    : : : :
    : : : :
    : : : Could you show some of the code, like parameter conversions?
    : : :
    : : :
    : : :
    : : :
    : : Thank you for your answer !
    : :
    : : You may find excerpts of the thunking unit on
    : : http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/win32_e.pas
    : : (see then WIN32_CREATEFILE or WIN32_OPENFILE function)
    : :
    : : and the calling program on
    : : http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/essai_e.pas
    : :
    : Hai, I took a good look at it, and can't see anything wrong.
    :
    : My suggestion is to test it with a nil pointer as file name. If this returns a error, but no access violation then this parameter is the problem. Otherwise its probably in the WIN32 unit.
    : Also can you post the exact error text? (I don't have BP7 running anymore, so I can't do the testing myself. B.t.w. why don't you use Delphi for win32 programming?)
    :
    :
    Your suggestion was right : when I pass nil as file name I get no access violation error and the function returns -1 as file handle as expected.
    The exact error message is [b]'ESSAI_E.EXE caused an access violation in NTDLL.DLL at 0x77F8882F'[/b].
    To answer your last question, my program resides on a server and must be used by 16-bit workstations as well as 32-bit ones. So I decided to write a 16-bit application that can use 32-bit functionalities when it's possible.



  • : [b][red]This message was edited by Alcatiz at 2004-6-20 22:39:11[/red][/b][hr]
    : : [b][red]This message was edited by Masterijn at 2004-6-18 4:14:47[/red][/b][hr]
    : : : : : Hi all !
    : : : : :
    : : : : : I'm trying to call the CreateFile function of kernel32.dll from a 16-bit program (written in BPW 7.0), using the [b]thunk functions[/b] of the 16-bit kernel (LoadLibraryEx32W, FreeLibrary32W, GetProcAddress32W, GetVDMPointer32W and CallProc32W).
    : : : : :
    : : : : : Under Windows NT 4.0 (SP6) and Windows 2000 Pro (SP4) I get an access violation error in NTDLL.DLL.
    : : : : :
    : : : : : I've verified all the parameters and I've converted all 16:16 pointers to linear addresses : it still doesn't work.
    : : : : : It's the first time I get an error with the thunk functions.
    : : : : :
    : : : : : Could someone explain me what's wrong ?
    : : : : :
    : : : : :
    : : : : Could you show some of the code, like parameter conversions?
    : : : :
    : : : :
    : : : :
    : : : :
    : : : Thank you for your answer !
    : : :
    : : : You may find excerpts of the thunking unit on
    : : : http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/win32_e.pas
    : : : (see then WIN32_CREATEFILE or WIN32_OPENFILE function)
    : : :
    : : : and the calling program on
    : : : http://users.skynet.be/lpjjl/Documentation/Pascal/Perso/essai_e.pas
    : : :
    : : Hai, I took a good look at it, and can't see anything wrong.
    : :
    : : My suggestion is to test it with a nil pointer as file name. If this returns a error, but no access violation then this parameter is the problem. Otherwise its probably in the WIN32 unit.
    : : Also can you post the exact error text? (I don't have BP7 running anymore, so I can't do the testing myself. B.t.w. why don't you use Delphi for win32 programming?)
    : :
    : :
    : Your suggestion was right : when I pass nil as file name I get no access violation error and the function returns -1 as file handle as expected.
    : The exact error message is [b]'ESSAI_E.EXE caused an access violation in NTDLL.DLL at 0x77F8882F'[/b].
    : To answer your last question, my program resides on a server and must be used by 16-bit workstations as well as 32-bit ones. So I decided to write a 16-bit application that can use 32-bit functionalities when it's possible.
    :
    :
    :
    :
    Finally it works !!!
    Thanks to your suggestion about the file name address, I've tried to translate the 16:16 address of the file name directly with the GetVDMPointer32W function and not to let the CallProc32W do it.
    I don't understand why it works now (but I enjoy it, as the problem haunted me for two months !). If someone can explain me...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories