?
Solved

Return bitmap

Posted on 2002-06-14
5
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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