How to use an external DLL written in C from DELPHI

I need to use an external dll to communicate with a digital camera, and I found a program with the corresponding DLL that allows me to communicate. In the dll description, I found a function that fits my needs. The DLL header looks like this ....

//-------------------------------------------------------------------
// ReleaseShutter()
// Inputs:
//   timeOutInSecs   timeout in secs to wait for picture to be
//                   taken and downloaded (max 60 secs)
//   pszFilename     option string in which to store the name of the
//                   saved image. Set to NULL if not required
//   numChars        length of pszFilename if defined
//
// Returns://   0 - Success, image saved
//   1 - PSRemote is not running
//   2 - PSRemote is running but camera is not connected
//   3 - Camera is busy
//   4 - Timeout waiting for image to be saved
//   5 - Error releasing shutter
//
// Description:
//   Take a picture and optionally wait for it to be saved to disk.
//
//--------------------------------------------------------------------
PSRemoteLIB_API int __stdcall ReleaseShutter( int timeoutInSecs,
                            char* Filename,int   numChars  );

Ok, I load the dll, use the function, get the status of the result, and the external program takes a picture, but I CAN’T RECEIVE A FILENAME BACK !!!! Here is my code

procedure TForm1.Button2Click(Sender: TObject);
var   Status: Integer;
Name1: PChar;
DLLHandle: Thandle;
TakePic: Function (T: Integer; Nam: Pchar;Num:Integer):Integer; {$IFDEF WIN32} stdcall; {$ENDIF}

 begin  DLLHandle := LoadLibrary('PSRemoteLib.dll');
   if DLLHandle >= 32 then { success }
     begin   
      Name1:=stralloc(1024);
      TakePic := GetProcAddress(DLLHandle, 'ReleaseShutter');
      Status:=TakePic(60,Name1,SizeOf(Name1));
      label1.Caption:=intTostr(Status);
      label2.Caption:=Name1;
      FreeLibrary(DLLHandle);
     end
   else     MessageDlg('Error: could not find PSRemoteLib.dll', mtError, [mbOk], 0);
  StrDispose(Name1);
end;

I try PChar PWidechar and everything I found on the net, but nothing !!!

What am I doing wrong???? In the .exe example that comes with the dll and works in cmd mode, this works fine !!!! The program accepts the image and file name of the report ???? I have an example source code and looks like this:

        case 0: // success            if (filename && strlen(filename))            
{
                cout << "Success, image saved as: " << filename << endl;            
}
            else            
{
                cout << "Success, image saved on CF card?" << endl;            
}
            break;
        case 1:            cerr << "PSRemote is not running" << endl;
            break;
        case 2:            cerr << "Camera is not connected" << endl;
            break;
        case 3:            cerr << "Camera is busy" << endl;
            break;
        case 4:            cerr << "Timeout waiting for image to be saved" << endl;
            break;
        default:
            cerr << "ERROR: unexpected return status: " << status << endl;        
}

}
    return nRetCode;
}

PLEASE HELP I need it !!!

PS dll

{///----------------------------------------------------------------------- }
{/// GetOutputPath() }
{/// Inputs: }
{/// pszPathname string in which to store the pathname of the }
{/// directory currently being used to save images }
{/// numChars length of pszPathname }
{/// }
{/// Returns: }
{/// 0 - Success, pathname returned in pszPathname }
{/// 1 - PSRemote is not running }
{/// 4 - Some other error }
{/// }
{/// Description: }
{/// Returns the full pathname of the directory used for saving images. }
{/// This is the base directory as specified by SetOutputPath() plus }
{/// any separate directories for year, month or day if selected in }
{/// preferences. }
{/// }
{///----------------------------------------------------------------------- }
var
  GetOutputPath: function(pszPathname: PChar; 
                          numChars: var Integer): SREMOTELIB_API INT __STDCALL cdecl  {$IFDEF WIN32} stdcall {$ENDIF}; 

ANd ( ) ,

+3
3

char. ,

Name1 : array[MAX_PATH+1] of AnsiChar;

MAX_PATH Windows . AnsiChar - Delphi equvalent ++ char

Status := TakePic(60,Name1,MAX_PATH);
+5

, , Delphi 2009 . PChar D2009 Unicode. PAnsiChar, .

+2

, . SizeOf, Name1, , . Name1 - PChar, SizeOf(Name1) SizeOf(PChar), 4. 1024 , 1024 ReleaseShutter:

Name1 := StrAlloc(1024);
TakePic := GetProcAddress(DLLHandle, 'ReleaseShutter')
Status:=TakePic(60, Name1, 1024);

Delphi 2009 , PChar PAnsiChar, DLL, .

+2

All Articles