试做了一个DLL,可运行时总是出错,代码如下:
library Project2;uses
  SysUtils,
  Classes,
  Graphics;{$R *.res}function PICtoBMP(PIC: TPicture): TBitmap;
begin
  Result := TBitmap.Create;
  Result.Assign(PIC.Graphic);
end;exports
  PICtoBMP;begin
end.这个函数直接在单元里调用是没有问题的,可是通过dll来调用总是提示Cannot assign a XXX to TBitmap,就算我传递的是一副BMP图像都是如此提示,感觉上assign方法不能使用不知道做dll应该注意些什么?

解决方案 »

  1.   

    应该不是DLL的问题 呵呵 我没用过DELPHI做DLL是你函数本身的问题把function PICtoBMP(PIC: TPicture): TBitmap;
    begin
      Result := TBitmap.Create;
      Result.Assign(PIC.Graphic);
    end;
    // 直接移到调用工程 测试一下
      

  2.   

    function PICtoBMP(PIC: TPicture): TBitmap;
    begin
      Result := TBitmap.Create; // 可能就是这个result的缘故了... 一般不要在DLL分配空间 传出
      Result.Assign(PIC.Graphic);
    end;一般是在调用方分配空间 然后DLL在里面改写,填充之类的...function PICtoBMP(PIC: TPicture;var BitMap:TBitmap):Boolean
    begin
      Result := False;
      if BitMap = nil then
        Exit;
      BitMap.Assign(PIC.Graphic);  Result := True;
    end;try this..
      

  3.   

    也是不行,关键不在这里,就算我的Result不创建,我还是要创建一个临时BMP图像才能完成任务;
      

  4.   

    library Project2;uses
      SysUtils,
      Classes,
      Graphics;{$R *.res}function PICtoBMP(PIC: TPicture): TBitmap; stdcall; //
    begin
      Result := TBitmap.Create;
      Result.Assign(PIC.Graphic);
    end;exports
      PICtoBMP;begin
      

  5.   

    library Project2;uses
      SysUtils,
      Classes,
      Graphics;{$R *.res}function PICtoBMP(PIC: TPicture): TBitmap; stdcall; //
    begin
      Result.Assign(PIC.Graphic);
    end;exports
      PICtoBMP;begin
      

  6.   

    我只是在delphi下调用,和stdcall没什么关系