Forum > Windows
Can my dll be used in another programming language
(1/1)
vkhoa:
I wrote a library like this
--- Code: ---library library_delegate;
uses Classes, SysUtils;
type commandevent=procedure (text:string);
var ocommand:commandevent;
procedure create(cmd:commandevent);stdcall;
begin
ocommand:=cmd;
end;
procedure writetext(text:string);stdcall;
begin
if assigned(ocommand) then
ocommand(text);
end;
exports create,writetext;
begin
end.
--- End code ---
then compiled it to "library_delegate.dll"
after that I wrote a program
--- Code: ---program use_library_delegate;
uses Classes, SysUtils;
type commandevent=procedure (text:string);
procedure create(cmd:commandevent);stdcall;external 'library_delegate';
procedure writetext(text:string);stdcall;external 'library_delegate';
procedure writeatext(text:string);
begin
writeln(text);
end;
var i:integer;
begin
create(@writeatext);
for i:=1 to 100 do
writetext('Text line '+inttostr(i));
readln;
end.
--- End code ---
the program run as I expected, it wrote 100 text line to the console
I want to know if this dll could be used in visual basic or C(or other windows programming language). And I am curious to know how simple it is to use the dll's function in those language (especially at passing the procedure type parameter in the "create" procedure), can you give me any examples.
another question, can we assign or read the "ocommand" directly from the program?
taazz:
--- Quote from: vkhoa on June 18, 2015, 08:54:28 am ---I want to know if this dll could be used in visual basic or C(or other windows programming language).
--- End quote ---
No it can't. You have to stop using the string data type if you want to be compatible. In short you can only use C compatible data types ee Char, pchar etc.
vkhoa:
:)Thanks for the reply!
Is visual basic compatible data types is the same as C compatible data types ?
And can we declare and pass the procedure type parameter in those language
and assume that I use the right data type, can it call successfully the procedure which was passed to "create" procedure when "writetext" is called
Can anyone tell me detail about the C an VB compatible data types, for example for byte, longint, ect...
taazz:
As far as I know yes Visual basic has the ability to pass a procedure/function address to your code. Make sure that you include the calling convention on your requirements and you are set.
Navigation
[0] Message Index