Solved

Return bitmap

Posted on 2002-06-14
5
229 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now