How do I correct this code

See code frag below.  The unit this code is included in compiles just fine but it fails after I make what appears to be a successful call to a function in a DLL.  I am able to debug right through the call and inspect the record contents that I am passing to the external function but when I try to access any of the contents it immediately raises an exception, if I remove the code that accesses the info in the record structure then it still raises an exception.  There are other functions I need to call that are part of this DLL but I need to get the most basic one to work first before I try to tackle the rest of them.  I am using Delphi 6 and using a 3rd party company's DLL which has C++ header file included.  Any help getting this to work with Delphi 6 would be appreciated.


type
  LUN1Type = (
    LUN1_NO_DEVICE {= -2},
    LUN1_NOT_EXISTS {= -1},
    LUN1_PUBLIC2 {= 0},
    LUN1_CDROM {= 1} );

  DrvInfoType = record
    bValid: Bool;
    publicSz: Word;
    securedSz: Word;
    totalSz: Word;
    lun1Sz: Word;
    productId: Word;
    vendorId: Word;
    eLUN1Type: LUN1TYPE;
    bLogin: Bool;
    bPwdRegistered: Bool;
    deviceStr: Array[0..255-1] of Char;
    productStr: Array[0..255-1] of Char;
    vendorStr: Array[0..255-1] of Char;
    serialIdStr: Array[0..255-1] of Char;
    lun0DrvLtStr: Array[0..255-1] of Char;
    lun1DrvLtStr: Array[0..255-1] of Char;
  end {DrvInfoType};

  DrvInfoDBType = record
    numOfDrv: Word;
    drvInfoAry: Array[0..5-1] of DRVINFOTYPE;
  end {DrvInfoDBType};

  PDrvInfo = ^DrvInfoDBType;

  TDriveInfo = function (var _1: DrvInfoDBType):Integer; StdCall;
.
.
.
.
.
procedure TfmPmpMain.FormShow(Sender: TObject);
var
      LibHandle      :Thandle;
      x                :Word;
      df                :TDriveInfo;
      di                :DrvInfoDBType;
begin
      LibHandle := LoadLibrary('DriveControlDLL.dll');
      try
            if LibHandle = 0 then
                  raise EDLLLoadError.Create('Unable to Load DLL');

            @df := GetProcAddress(LibHandle, 'USB007_RetrieveDriveInfoDB');

            if not (@df = nil) then
            begin
                  x := df(di);
            end
            else
                  RaiseLastWin32Error;
      finally
            FreeLibrary(LibHandle);
      end;
end;                        

axp275Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
That kind of error is probably a calling convention or parameter type error.
can you post the C++ header ?

will it changes something if you declare this (I changed TDriveInfo type as f_DriveInfo to tell it's a function type ) :

  f_DriveInfo = function (_1: PDrvInfo ):Integer; StdCall;

and call like that :
   x := df(@di);

Is suspect it won't change anything, but that's worth a try
0
cebassoCommented:
Can you attach the headers here?
at least, the important part... what you showed for example
0
axp275Author Commented:
Here is the converted Header file.  This will not compile when I include it so I took the record structures and declared them in the unit where I need them.  The compile error happens on the section where the macro is declared...... DRIVECONTROLDLL_API = __declspec(dllexport);

Since I couldn't compile I decided to use the parts of the code I felt that I needed but that doesn't work either.  


unit DRIVECONTROLDLL;
{**************************************************************************}
{                                                                          }
{    This C DLL header file first (automatic) conversion generated by:     }
{    HeadConv 4.0 (c) 2000 by Bob Swart (aka Dr.Bob - www.drbob42.com)     }
{      Final Delphi-Jedi (Darth) command-line units edition                }
{                                                                          }
{    Generated Date:   4/7/2010                                            }
{    Generated Time: 6:13:43 AM                                              }
{                                                                          }
{**************************************************************************}

interface
uses
{$IFDEF WIN32}
  Windows;
{$ELSE}
  Wintypes, WinProcs;
{$ENDIF}


{=> c:\dev6\vd6\usb007\drivecontrolcmd\DRIVECONTROLDLL.H <=}


{$IFNDEF __DRIVECONTROLDLL_H__}
{$DEFINE __DRIVECONTROLDLL_H__}

{$DEFINE DRIVECONTROLDLL_EXPORTS}

{/// The following ifdef block is the standard way of creating macros which make exporting }
{/// from a DLL simpler. All files within this DLL are compiled with the DRIVECONTROLDLL_EXPORTS }
{/// symbol defined on the command line. this symbol should not be defined on any project }
{/// that uses this DLL. This way any other project whose source files include this file see }
{/// DRIVECONTROLDLL_API functions as being imported from a DLL, wheras this DLL sees symbols }
{/// defined with this macro as being exported. }

{$IFDEF DRIVECONTROLDLL_EXPORTS}
const
  DRIVECONTROLDLL_API = __declspec(dllexport);
{$ELSE}
const
  DRIVECONTROLDLL_API = __declspec(dllimport);
{$ENDIF}


{/// Return Codes }
{/// }
const
  R_OK = 0;
const
  R_FAIL = -1;
const
  R_INDEX_OUT_OF_RANGE = -2;

type
  BOOL = Integer;


{/// Drive info database record structure }
{/// }
type
  LUN1Type = (
    LUN1_NO_DEVICE {= -2},
    LUN1_NOT_EXISTS {= -1},
    LUN1_PUBLIC2 {= 0},
    LUN1_CDROM {= 1} );

type
  DrvInfoType = record
    bValid: Bool;
    publicSz: Word;
    securedSz: Word;
    totalSz: Word;
    lun1Sz: Word;
    productId: Word;
    vendorId: Word;
    eLUN1Type: LUN1TYPE;
    bLogin: Bool;
    bPwdRegistered: Bool;
    deviceStr: Array[0..255-1] of Char;
    productStr: Array[0..255-1] of Char;
    vendorStr: Array[0..255-1] of Char;
    serialIdStr: Array[0..255-1] of Char;
    lun0DrvLtStr: Array[0..255-1] of Char;
    lun1DrvLtStr: Array[0..255-1] of Char;
  end {DrvInfoType};

type
  DrvInfoDBType = record
    numOfDrv: Word;
    drvInfoAry: Array[0..5-1] of DRVINFOTYPE;
  end {DrvInfoDBType};

{$IFDEF __cplusplus // If used by C++ code,}
{$ENDIF}

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_RetrieveDriveInfoDB }
{/// Parameters: [in/out] DrvInfoDBType - contains all drive info }
{/// Description: Read drive info of all valid USB007 drives and shovel into a big structure. }
{/// Return: R_OK - if successful. }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_RetrieveDriveInfoDB(var _1: DRVINFODBTYPE): {DRIVECONTROLDLL_API} cdecl  {$IFDEF WIN32} stdcall {$ENDIF};

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_SetWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive write-protect mode on. This function requires admin-mode on WinXP. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_SetWriteProtectDrive(drvIdx: Integer): {DRIVECONTROLDLL_API} cdecl  {$IFDEF WIN32} stdcall {$ENDIF};

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_UnSetWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive write-protect mode off. This function requires admin-mode on WinXP. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_UnSetWriteProtectDrive(drvIdx: Integer): {DRIVECONTROLDLL_API} cdecl  {$IFDEF WIN32} stdcall {$ENDIF};

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_SetTempWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive temporary write-protected. This function may work only if }
{/// write-protect mode is on. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_SetTempWriteProtectDrive(drvIdx: Integer): {DRIVECONTROLDLL_API} cdecl  {$IFDEF WIN32} stdcall {$ENDIF};

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_UnSetTempWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive temporary writable. The writable status will lose after }
{/// dismount. This function may work only if write-protect mode is on. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_UnSetTempWriteProtectDrive(drvIdx: Integer): {DRIVECONTROLDLL_API} cdecl  {$IFDEF WIN32} stdcall {$ENDIF};

{$IFDEF __cplusplus // If used by C++ code,}
{$ENDIF}

{$ENDIF}

implementation

function USB007_RetrieveDriveInfoDB; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_SetWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_UnSetWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_SetTempWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_UnSetTempWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';

end.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

axp275Author Commented:
In addition, the aforementioned pascal header was generated from the original C++ header by DrBob's headconv utility.  I need to make calls from a Delphi 6 app to the functions listed above.  All I got from the provider was a dll, the C++ header and a command line utility.  I would like to get our app to be able to work with the library.  The first code frag showed what I did myself using the information from the converted header file because when I included the header as converted to pascal it would not compile past the __cdecl.....macro.  In desperation I pulled code from it and bypassed the header and put into the unit where I need it.  Anyway, if you have any other questions feel free.

Thanks.
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
as I said :
>That kind of error is probably a calling convention or parameter type error.

by declaring the function type as stdcall, where it is in fact cdecl, you are telling the compiler that the function is responsible for the cleaning of the parameters in the stack, where cdecl state the opposite : it's the caller that is responsible for it. So when you return from this call, you corrupt the stack, and this can only lead to a quick death of your application.

use the cdecl convention call instead of stdcall :
  TDriveInfo = function (var _1: DrvInfoDBType):Integer; cdecl;

Open in new window

0
Emmanuel PASQUIERFreelance Project ManagerCommented:
The automatic conversion from C++ header to pascal is a pile of junk. Can you post the real .H file so that a human can do it correctly ?
0
axp275Author Commented:
Sure, here it is.  I'll admit I had to make some changes but aside from the macro __declspect(....) that doesn't compile it has saved me some time in the past.  Here is the .h


#ifndef __DRIVECONTROLDLL_H__
#define __DRIVECONTROLDLL_H__

// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the DRIVECONTROLDLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// DRIVECONTROLDLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef DRIVECONTROLDLL_EXPORTS
#define DRIVECONTROLDLL_API __declspec(dllexport)
#else
#define DRIVECONTROLDLL_API __declspec(dllimport)
#endif

// Return Codes
//
#define R_OK      0
#define R_FAIL      -1
#define R_INDEX_OUT_OF_RANGE      -2

typedef int      BOOL;
 

// Drive info database record structure
//
typedef      enum
{
      LUN1_NO_DEVICE = -2,
      LUN1_NOT_EXISTS = -1,
      LUN1_PUBLIC2 = 0,
      LUN1_CDROM = 1,
} LUN1Type;

typedef struct
{
      BOOL                  bValid;
      unsigned int      publicSz;
      unsigned int      securedSz;
      unsigned int      totalSz;
      unsigned int      lun1Sz;
      unsigned short      productId;
      unsigned short      vendorId;
      LUN1Type            eLUN1Type;
      BOOL                  bLogin;
      BOOL                  bPwdRegistered;
      char                  deviceStr[255];
      char                  productStr[255];
      char                  vendorStr[255];
      char                  serialIdStr[255];
      char                  lun0DrvLtStr[255];
      char                  lun1DrvLtStr[255];
} DrvInfoType;

typedef struct
{
      unsigned int      numOfDrv;
      DrvInfoType            drvInfoAry[5];
} DrvInfoDBType;

#ifdef __cplusplus    // If used by C++ code,
extern "C" {          // we need to export the C interface
#endif

// -----------------------------------------------------------------------------------------
// Function:      USB007_RetrieveDriveInfoDB
// Parameters:      [in/out] DrvInfoDBType - contains all drive info
// Description: Read drive info of all valid USB007 drives and shovel into a big structure.
// Return:            R_OK - if successful.
//              R_FAIL - misc. failure.
// ------------------------------------------------------------------------------------------
DRIVECONTROLDLL_API int USB007_RetrieveDriveInfoDB(DrvInfoDBType *);

// -----------------------------------------------------------------------------------------
// Function:      USB007_DC_SetWriteProtectDrive
// Parameters:      drvIdx - drive index starting from 0
// Description: Set drive write-protect mode on. This function requires admin-mode on WinXP.
// Return:            R_OK - if successful.
//                        R_INDEX_OUT_OF_RANGE - drive index is out of range
//              R_FAIL - misc. failure.
// ------------------------------------------------------------------------------------------
DRIVECONTROLDLL_API int USB007_DC_SetWriteProtectDrive(int drvIdx);

// -----------------------------------------------------------------------------------------
// Function:      USB007_DC_UnSetWriteProtectDrive
// Parameters:      drvIdx - drive index starting from 0
// Description: Set drive write-protect mode off. This function requires admin-mode on WinXP.
// Return:            R_OK - if successful.
//                        R_INDEX_OUT_OF_RANGE - drive index is out of range
//              R_FAIL - misc. failure.
// ------------------------------------------------------------------------------------------
DRIVECONTROLDLL_API int USB007_DC_UnSetWriteProtectDrive(int drvIdx);

// -----------------------------------------------------------------------------------------
// Function:      USB007_DC_SetTempWriteProtectDrive
// Parameters:      drvIdx - drive index starting from 0
// Description: Set drive temporary write-protected. This function may work only if
//                        write-protect mode is on.
// Return:            R_OK - if successful.
//                        R_INDEX_OUT_OF_RANGE - drive index is out of range
//              R_FAIL - misc. failure.
// ------------------------------------------------------------------------------------------
DRIVECONTROLDLL_API int USB007_DC_SetTempWriteProtectDrive(int drvIdx);

// -----------------------------------------------------------------------------------------
// Function:      USB007_DC_UnSetTempWriteProtectDrive
// Parameters:      drvIdx - drive index starting from 0
// Description: Set drive temporary writable. The writable status will lose after
//              dismount. This function may work only if write-protect mode is on.
// Return:            R_OK - if successful.
//                        R_INDEX_OUT_OF_RANGE - drive index is out of range
//              R_FAIL - misc. failure.
// ------------------------------------------------------------------------------------------
DRIVECONTROLDLL_API int USB007_DC_UnSetTempWriteProtectDrive(int drvIdx);

#ifdef __cplusplus    // If used by C++ code,
}                            // we need to export the C interface
#endif

#endif
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
here it is. The main problem was probably a conversion from unsigned int to word instead of Cardinal, leading to a structure of a lesser size. So if in the dll function the structure was initialized, an access violation would occur. So the problem is probably not one of calling convention and crash upon return, but really inside the function.

unit DRIVECONTROLDLL;

interface

uses Windows;

{/// Return Codes }
const
  R_OK = 0;
  R_FAIL = -1;
  R_INDEX_OUT_OF_RANGE = -2;

  LUN1_NO_DEVICE = -2;
  LUN1_NOT_EXISTS = -1;
  LUN1_PUBLIC2 = 0;
  LUN1_CDROM = 1;

type
  LUN1TYPE = LUN1_NO_DEVICE..LUN1_CDROM;
  DRVCONTROL_RET = R_INDEX_OUT_OF_RANGE..R_OK;

{/// Drive info database record structure }

  DrvInfoType = record
    bValid      : Boolean;
    publicSz    : Cardinal;
    securedSz   : Cardinal;
    totalSz     : Cardinal;
    lun1Sz      : Cardinal;
    productId   : Word;
    vendorId    : Word;
    eLUN1Type   : LUN1TYPE;
    bLogin      : Boolean;
    bPwdRegistered: Boolean;
    deviceStr   : Array[0..255-1] of Char;
    productStr  : Array[0..255-1] of Char;
    vendorStr   : Array[0..255-1] of Char;
    serialIdStr : Array[0..255-1] of Char;
    lun0DrvLtStr: Array[0..255-1] of Char;
    lun1DrvLtStr: Array[0..255-1] of Char;
  end;

type
  DrvInfoDBType = record
    numOfDrv: Cardinal;
    drvInfoAry: Array[0..5-1] of DRVINFOTYPE;
  end;


{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_RetrieveDriveInfoDB }
{/// Parameters: [in/out] DrvInfoDBType - contains all drive info }
{/// Description: Read drive info of all valid USB007 drives and shovel into a big structure. }
{/// Return: R_OK - if successful. }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_RetrieveDriveInfoDB(var DrvInfo: DRVINFODBTYPE): DRVCONTROL_RET; stdcall;

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_SetWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive write-protect mode on. This function requires admin-mode on WinXP. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_SetWriteProtectDrive(drvIdx: Integer): DRVCONTROL_RET; stdcall;

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_UnSetWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive write-protect mode off. This function requires admin-mode on WinXP. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_UnSetWriteProtectDrive(drvIdx: Integer): DRVCONTROL_RET; stdcall;

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_SetTempWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive temporary write-protected. This function may work only if }
{/// write-protect mode is on. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_SetTempWriteProtectDrive(drvIdx: Integer): DRVCONTROL_RET; stdcall;

{/// ----------------------------------------------------------------------------------------- }
{/// Function: USB007_DC_UnSetTempWriteProtectDrive }
{/// Parameters: drvIdx - drive index starting from 0 }
{/// Description: Set drive temporary writable. The writable status will lose after }
{/// dismount. This function may work only if write-protect mode is on. }
{/// Return: R_OK - if successful. }
{/// R_INDEX_OUT_OF_RANGE - drive index is out of range }
{/// R_FAIL - misc. failure. }
{/// ------------------------------------------------------------------------------------------ }

function USB007_DC_UnSetTempWriteProtectDrive(drvIdx: Integer): DRVCONTROL_RET; stdcall;


implementation

function USB007_RetrieveDriveInfoDB; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_SetWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_UnSetWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_SetTempWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';
function USB007_DC_UnSetTempWriteProtectDrive; external 'DRIVECONTROLDLL.DLL';

end.

Open in new window

0
axp275Author Commented:
My program still crashes with the same error as before:

Uses
........, DriveControlDLL;

in the formshow I am making the following call:

X := USB007_RetrieveDriveInfoDB(di);

The program runs past this call and my showmessage is displaying the correct information retrieved from the record passed to the aforementioned func.  Somewhere after that the CPU window comes up and says "Access Violation at 0x00000000.........".

I am including the header file you provided as shown above in the uses clause then I am calling the function listed above.  Is there anything else I should be doing to make a clean call which doesn't result in an Access Violation?

This code frag below is mostly code that has been commented out.

(*      LibHandle := LoadLibrary('DriveControlDLL.dll');
      try
              if LibHandle = 0 then
                  raise EDLLLoadError.Create('Unable to Load DLL');

    @df := GetProcAddress(LibHandle, 'USB007_RetrieveDriveInfoDB');

    if (@df <> nil) then
    begin
      x := df(di);
          ShowMessage(IntToStr(x) + IntToStr(di.numOfDrv)+di.drvInfoAry[0].serialIdStr);
    end
    else
      RaiseLastWin32Error;
*)      
     
            x := USB007_RetrieveDriveInfoDB(di);
(*
      finally
            FreeLibrary(LibHandle); // Unload the DLL.
      end;
*)  

This is the method I was using before.  Should I still be using this approach or can I just call the functions as I did?  

Again, thanks.
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
can you post the dll ?
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
I am still unsure if the dll as been compiled with cdecl or stdcall convention. Maybe you could try with cdecl for each function declaration in the unit

0
axp275Author Commented:
I'm not sure if I can post the DLL.   Is there an email address I could use to send an url for download?  I will make the change using cdecl and test and get right back to you.
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
you can post the url here
otherwise : epasquier@tmtsa.fr
0
axp275Author Commented:
ok, I changed the declaration to use cdecl instead of stdcall and now the program will run, right after the call to the driveinfo function it returns a usable chunk of data that look correct and then it gives an access violation (0x00000) but, when I use stdcall it will give the AV and the program will not continue.  Using cdecl it will raise the exception referring to the same address (access viol) and then after clicking ok it will allow the program to continue running.  
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
the link doesn't work. can you send the dll by mail ?
0
axp275Author Commented:
done
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
I can call the function in the unit I provided, it does not crash but it returns code -1 (FAIL)
I suppose I'm missing some hardware, what this dll is supposed to do ?

Check that you are using this unit the same way I do :

If you can execute that code and tell me where it fails exactly for you when executing step by step, maybe we can sort it out
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    mmo1: TMemo;
    procedure btn1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

Uses DriveControlDll;


procedure TForm1.btn1Click(Sender: TObject);
Var
 DrvInfo: DRVINFODBTYPE;
 Ret:DRVCONTROL_RET;
begin
 FillChar(DrvInfo,sizeof(DrvInfo),0); // Initialize structure : probably not necessary
 Ret:=USB007_RetrieveDriveInfoDB(DrvInfo);
 mmo1.Lines.Add(Format('Ret=%d',[Ret]));
 if Ret=R_OK Then
  begin
   mmo1.Lines.Add(Format('Nb Drives = %d',[DrvInfo.numOfDrv]));
  end;
end;


end.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
axp275Author Commented:
ok still crashes but only when the flash drive is installed.  Same access violation.

0
Emmanuel PASQUIERFreelance Project ManagerCommented:
what does this dll do ? how can I test it also and reproduce the same error you have ?
0
axp275Author Commented:
The DLL provides access to a USB flash drive.  It is used for administration of the flash drive and the contents.
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
is it supposed to give something with any USB key for example ? or just some particular hardware ?
I want to know if I have a chance to test it with what I have
0
axp275Author Commented:
The library is specific to a type of flash drive we are going to use for our software project.  The DLL gives us access to the information on the drive (vendorid, serial number, etc...).  We will be using this information to control functions of our software that will run from that flash drive.  I don't know of any way for you to test it w/o having one of these flash drives.  It won't work on any other flash drive.  I used your example code and compared it to what I was doing and the two are nearly identical.  Both fail exactly the same way but only fail when the flash drive is plugged in.  When it is removed the program will run just fine, yours and mine.  I have contacted the manufacturer and they have indicated that they are willing to help.  I expect to hear from them tomorrow.  I'll let you know what happens.  Your help has been great and regardless of if the solution is found I will assign the points to you because some of your guidance has been very useful to me.  Thank you.
0
axp275Author Commented:
We did not completely solve the problem but the assistance elevated the functionality of the program significantly.  Thank you Epasquier
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.