Still struggling ...
This code works as expected (shows "Cornerstone C++ DLL version 3.01")
function MyGetLibraryVersion: PChar; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF}; external Oriel_USB_DLL index 5;
procedure TMainForm.FormCreate(Sender: TObject);
const
Oriel_USB_DLL = 'Oriel_USB.dll';
var
hOriel_USB_DLL: THandle;
p: PChar;
s: string;
begin
hOriel_USB_DLL:= LoadLibrary(PChar(Oriel_USB_DLL));
p:= MyGetLibraryVersion();
s:= StringReplace(StrPas(p),#13,'',[rfReplaceAll]);
Memo.Lines.Add(s);
FreeLibrary(hOriel_USB_DLL);
end;
end.
Without line 28 (
hOriel_USB_DLL:= LoadLibrary(PChar(Oriel_USB_DLL));) it shows "No Device Found."
If I change the code in FormCreate to
hOriel_USB_DLL:= LoadLibrary(PChar(Oriel_USB_DLL));
p:= MyGetLibraryVersion();
s:= StringReplace(StrPas(p),#13,'',[rfReplaceAll]);
Memo.Lines.Add(s); // "Cornerstone C++ DLL version 3.01"
p:= MyGetLibraryVersion();
s:= StringReplace(StrPas(p),#13,'',[rfReplaceAll]);
Memo.Lines.Add(s); // "No Device Found."
FreeLibrary(hOriel_USB_DLL);
the 1st call of MyGetLibraryVersion shows "Cornerstone C++ DLL version 3.01" and the 2nd call shows "No Device Found."
After adding another "
hOriel_USB_DLL:= LoadLibrary(PChar(Oriel_USB_DLL));" before the 2nd call to MyGetLibraryVersion I get "Cornerstone C++ DLL version 3.01" twice.
It seems that the DLL needs to be loaded again for every function call, is that to be expected?
Furthermore: when calling other DLL functions (that actually require data exchange with the monochromator) such as "Send" or "Query" (see earlier post) the program hangs when calling the function.
So I have the impression that I can access the DLL functions, but that these do not communicate with the monochromator.
In C code snippet provided by Oriel a "COriel_USB" class object is created and the DLL functions are called via this object:
COriel_USB myDevice;
myDevice.Send(strCommand);
Maybe that is the way it should be done.
But how to do that in Freepascal?
"COriel_USB" is found in the DLL with DLL expert viewer:
public: __thiscall COriel_USB::COriel_USB(void) 0x100034d0 0x000034d0 1 (0x1) Oriel_USB.dll C:\aaa\Oriel_USB.dll Exported Function
public: __thiscall COriel_USB::~COriel_USB(void) 0x100035e0 0x000035e0 2 (0x2) Oriel_USB.dll C:\aaa\Oriel_USB.dll Exported Function
But as a function?