Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Return bitmap

Posted on 2002-06-14
5
Medium Priority
?
262 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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

636 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