Solved

Return bitmap

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

13 Experts available now in Live!

Get 1:1 Help Now