delphi dll源码如下:
library tran2png;
uses
ShareMem, SysUtils, pngimage, Graphics, Classes, Dialogs, Controls;{$R *.res}function png2bmp():integer;stdcall;
var
Bitmap: TBitmap;
PNG: TPNGObject;
begin
PNG := TPNGObject.Create;
Bitmap := TBitmap.Create;
result := -1;
try
PNG.LoadFromFile('E:\海典\工作日志\0419\IMG00000501.png');
//PNG.LoadFromFile(pchar(Source));
Bitmap.Assign(PNG); //Convert data into bitmap
Bitmap.SaveToFile('E:\海典\工作日志\0419\t2.bmp');
result := 1;
finally
PNG.Free;
Bitmap.Free;
end
end;exports
png2bmp;beginend.pb中的定义:
function integer png2bmp() Library "tran2png.dll"pb中调用如下:
integer n
n = png2bmp()
messagebox('',string(n))运行没问题,就是关闭程序提示非法操作,望高人指点,谢谢了!
library tran2png;
uses
ShareMem, SysUtils, pngimage, Graphics, Classes, Dialogs, Controls;{$R *.res}function png2bmp():integer;stdcall;
var
Bitmap: TBitmap;
PNG: TPNGObject;
begin
PNG := TPNGObject.Create;
Bitmap := TBitmap.Create;
result := -1;
try
PNG.LoadFromFile('E:\海典\工作日志\0419\IMG00000501.png');
//PNG.LoadFromFile(pchar(Source));
Bitmap.Assign(PNG); //Convert data into bitmap
Bitmap.SaveToFile('E:\海典\工作日志\0419\t2.bmp');
result := 1;
finally
PNG.Free;
Bitmap.Free;
end
end;exports
png2bmp;beginend.pb中的定义:
function integer png2bmp() Library "tran2png.dll"pb中调用如下:
integer n
n = png2bmp()
messagebox('',string(n))运行没问题,就是关闭程序提示非法操作,望高人指点,谢谢了!
function png2bmp(fname : pchar):integer;stdcall;
var
Bitmap: TBitmap;
PNG: TPNGObject;
begin
showmessage(strpas(fname));
PNG := TPNGObject.Create;
Bitmap := TBitmap.Create;
result := -1;
try
PNG.LoadFromFile('E:\海典\工作日志\0419\IMG00000501.png');
//PNG.LoadFromFile(pchar(Source));
Bitmap.Assign(PNG); //Convert data into bitmap
Bitmap.SaveToFile('E:\海典\工作日志\0419\t2.bmp');
result := 1;
finally
PNG.Free;
Bitmap.Free;
end
end;pb定义如下:
function integer png2bmp(ref string fname) Library "tran2png.dll"
pb调用如下:
t1 ='E:\IMG00000501.png'
n = png2bmp(t1)
我在delphi中只能取到第一个字母 “E”
请问问题在那,谢谢
function integer png2bmp(ref string fname) Library "tran2png.dll"
修改为:
pb定义如下:
function integer png2bmp(string fname) Library "tran2png.dll"不要使用ref
把数据大小也传进去,就可以拷贝了