Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XE6, Win7: file writing in DLLs not working


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 3 - Last Post: May 30, 2014 7:39 AM Last Post By: Jeff Overcash (...
Jouni Pohjola

Posts: 2
Registered: 6/27/14
XE6, Win7: file writing in DLLs not working  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2014 1:00 AM
Hello

A really dumb newbie problem here I hope. Never used Delphi before last week and haven't developed executables for a Windows machine since mid-90's so please bear with me.

I have Delphi XE6 Version 20.0.15596.9843 (evaluation at this time) and I'm compiling a Win32 target on a Windows 7 64-bit Service Pack 1 machine.

The problem I'm having is as follows: I have a Delphi (Pascal) app that's supposed to handle GUI while a DLL library (of originally C++ routines) handles the main business logic of the program, including the majority of the file IO. The Delphi part has been ported from some older version (from ca. 2008) to XE6 (evaluation version at this time). An .exe compiled under the old system works insofar as file IO through DLL routines is concerned. However the new .exe I'm getting from compiling my project isn't. When a file IO DLL routine get called, no exceptions are raised nor is there any internal error code from the routine, it just fails to produce the target file. File handles don't get passed to or from the "black box" routines, just the file names (full pathnames). It's as if, in UNIX terms, they were writing to /dev/null instead of the file specified.

At this time I'm not privy to the C++ part source code (although the situation may change shortly) so I can't tell exactly what each routine is attempting to do. I've just been handed the DLLs and (partial) header files. But since the system worked with the older version I'm thinking this must some pretty trivial mistake I'm making at the linking/compiling time but I can't figure out how to fix it.

Edited by: Jouni Pohjola on May 30, 2014 1:01 AM
David Millington

Posts: 257
Registered: 5/29/05
Re: XE6, Win7: file writing in DLLs not working
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2014 1:28 AM   in response to: Jouni Pohjola in response to: Jouni Pohjola
Jouni Pohjola wrote:
The problem I'm having is as follows: I have a Delphi (Pascal) app that's supposed to handle GUI while a DLL library (of originally C++ routines) handles the main business logic of the program, including the majority of the file IO. The Delphi part has been ported from some older version (from ca. 2008) to XE6 (evaluation version at this time). An .exe compiled under the old system works insofar as file IO through DLL routines is concerned. However the new .exe I'm getting from compiling my project isn't. When a file IO DLL routine get called, no exceptions are raised nor is there any internal error code from the routine, it just fails to produce the target file. File handles don't get passed to or from the "black box" routines, just the file names (full pathnames). It's as if, in UNIX terms, they were writing to /dev/null instead of the file specified.

Can you give an example of the interface that you call to do IO, please?

The first thing that jumps to mind is that the DLL expects ANSI filenames/paths and the modern Delphi (if you were using D2007 not D2009 before) is now giving it Unicode paths.
Jouni Pohjola

Posts: 2
Registered: 6/27/14
Re: XE6, Win7: file writing in DLLs not working  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2014 1:47 AM   in response to: David Millington in response to: David Millington
David M wrote:
Can you give an example of the interface that you call to do IO, please?

Pertinent definitions:
keyvec = array[0..31] of Byte;
function salaaTiedosto( inFile, outFile: PChar; key: keyvec ): integer; cdecl;

And the call:
AESkey: keyvec;
sp,sc : string;
...
tulos:=salaaTiedosto(PChar(sp),PChar(sc),AESkey);

The first thing that jumps to mind is that the DLL expects ANSI filenames/paths and the modern Delphi (if you were using D2007 not D2009 before) is now giving it Unicode paths.

I'll try and check that.

And sure enough, using ANSI strings as filenames solves this. Thanx a billion, I wouldn't have thought about that without either reading tons of documentation first or else seeing what the C++ routine actually does.

Edited by: Jouni Pohjola on May 30, 2014 1:53 AM

Edited by: Jouni Pohjola on May 30, 2014 1:56 AM
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: XE6, Win7: file writing in DLLs not working [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2014 7:39 AM   in response to: Jouni Pohjola in response to: Jouni Pohjola
Jouni Pohjola wrote:
David M wrote:
Can you give an example of the interface that you call to do IO, please?

Pertinent definitions:
keyvec = array[0..31] of Byte;
function salaaTiedosto( inFile, outFile: PChar; key: keyvec ): integer; cdecl;

And the call:
AESkey: keyvec;
sp,sc : string;
...
tulos:=salaaTiedosto(PChar(sp),PChar(sc),AESkey);

The first thing that jumps to mind is that the DLL expects ANSI filenames/paths and the modern Delphi (if you were using D2007 not D2009 before) is now giving it Unicode paths.

I'll try and check that.

And sure enough, using ANSI strings as filenames solves this. Thanx a billion, I wouldn't have thought about that without either reading tons of documentation first or else seeing what the C++ routine actually does.

Edited by: Jouni Pohjola on May 30, 2014 1:53 AM

Edited by: Jouni Pohjola on May 30, 2014 1:56 AM

If it was PChar in D2008, it is PAnsiChar in D2009 and up.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted corridors of Whitehall.
(Fish)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02