Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use external dll and get results ?

Status
Not open for further replies.

snmza

Technical User
Jun 9, 2008
3
0
0
RS
I need to use external dll to communicate with digital camera and I found program with appropriate dll that enable communication.
In dll description I found function that suits my needs. 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* pszFilename,
int numChars
);

Ok, I load dll, use function an get status and external program takes a picture but
I CAN NOT GET 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);
Slikaj := GetProcAddress(DLLHandle, 'ReleaseShutter');

Status:=TakePic(60,Name1,SizeOf(Name1));

edit1.Text:
label1.Caption:=intTostr(Status);
label2.Caption:=Name;

FreeLibrary(DLLHandle);
end
else
MessageDlg('Error: could not find PSRemoteLib.dll', mtError, [mbOk], 0);


StrDispose(Name1);


end;

What I do wrong ???? In the sample .exe that comes with dll and runs in cmd mode this works fine !!!! Program takes picture and report filename ????
I have a sample source code and looks like this

// take a single shot and report the filename/status
char filename[256];
int status = ReleaseShutter(60, filename, sizeof(filename));
switch(status)
{
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 !!!
 
Code:
 Name1: PChar;

PChar is a pointer to a character. In your code you have it pointing to nothing (as far as I can tell). See in the C sample:

Code:
 char filename[256];

It explicitly allocates 256 bytes.

Try defining as:

Code:
Name1: Array[0..255] of char;

And then code from there.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Couldn't help but to notice 255 instead of 256... I assume this is because the index is starting from 0 in Delphi and from 1 in C?


JD Solutions
 
in C, tables or arrays are defined by quantity and not range as in Pascal. "char filename[256]" defines 256 characters to be identified as "filename" in the code. When it comes to accessing the array/table, C is zero-based.

What I suggested is the C equivalent for the table in Delphi/Pascal.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
In 'C' arrays always index from 0.
C[256] defines an array of 256 elements 0 to 255


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top