Solved

Return bitmap

Posted on 2002-06-14
5
246 Views
Last Modified: 2013-12-03
How to return tbitmap object form dll when I call function form my application?
0
Comment
Question by:mmaxim
5 Comments
 
LVL 3

Expert Comment

by:SteveWaite
ID: 7079201
Do a search for madshi's dll example of hooking the keyboard. There you will see with memory mapped file to share memory so you can pass the bitmap from the dll. Look up CreateFileMapping() api.
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7079355
DLL:
library PicDLL;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  Graphics;

{$R *.RES}

Function ShowMeThePic(picname:string):TBitmap;stdcall;
begin
  Result:=TBitmap.create;
  Result.LoadFromFile(Picname);
end;


Exports ShowMeThePic;

begin
end.
 





App:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
 Function ShowMeThePic(picname:string):Tbitmap;stdcall;external 'picdll.dll';
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
image1.picture.bitmap:=ShowMeThePic('mybmp.bmp');
end;

end.
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 200 total points
ID: 7079441
Some time ago haved same problem . Thanks to Madshi for help:)

program YourProgram;

[...]

function DearDll_PleaseGiveMeABmp : dword; stdcall; external 'YourDll.dll';

procedure TForm1.Button1Click(Sender: TObject);
var bmp : TBitmap;
begin
 bmp := TBitmap.Create;
 bmp.Handle := DearDll_PleaseGiveMeABmp;
 Canvas.Draw(0, 0, bmp);
 bmp.Free;
end;

end.

library YourDll;

var GlobalBmp : TBitmap;

function DearDll_PleaseGiveMeABmp : dword; stdcall;
begin
 result := GlobalBmp.handle;
end;

exports DearDll_PleaseGiveMeABmp;

begin
 GlobalBmp := TBitmap.Create;
 GlobalBmp.LoadFromFile(...);
end.

0
 

Author Comment

by:mmaxim
ID: 7079543
That's it. Thanks for this clear example. Thanks DrDelphi, too...
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7080076
Anytime with pleasure :)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question