Solved

Delphi COM Programming need help accessing a COM object

Posted on 2009-03-30
7
689 Views
Last Modified: 2013-11-23
I have a project with a com object import of a .Net control. The control is functional but I need to use a command getBitmap which returns a _Bitmap or a _Image object.

_Image and _Bitmap are declared in System_Drawing_TLB which is created from Com import of System.Drawing.tlb  this is attached below.

when I  access any of these objects I can only access the standard COM calls,
GetTypeInfoCount
GetTypeInfo
GetIDsofNames
Invoke
QueryInterface
_Addref
_Release

no additional functions to work as an Image or Bitmap.

Does anyone know how to access the contents of the _TImage or _TBitmap as an image or a bitmap?

Thanks in advance

Cheers

Matt



unit System_Drawing_TLB;

 

// ************************************************************************ //

// WARNING                                                                    

// -------                                                                    

// The types declared in this file were generated from data read from a       

// Type Library. If this type library is explicitly or indirectly (via        

// another type library referring to this type library) re-imported, or the   

// 'Refresh' command of the Type Library Editor activated while editing the   

// Type Library, the contents of this file will be regenerated and all        

// manual modifications will be lost.                                         

// ************************************************************************ //

 

// $Rev: 8291 $

// File generated on 24/10/2008 13:17:13 from Type Library described below.

 

// ************************************************************************  //

// Type Lib: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.tlb (1)

// LIBID: {D37E2A3E-8545-3A39-9F4F-31827C9124AB}

// LCID: 0

// Helpfile: 

// HelpString: System.Drawing.dll

// DepndLst: 

//   (1) v2.0 stdole, (C:\Windows\system32\stdole2.tlb)

//   (2) v2.0 mscorlib, (C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb)

// Parent TypeLibrary:

//   (0) v1.0 geobase_com, (C:\Program Files\Telogis\GeoBase\bin\geobase.com.tlb)

// ************************************************************************ //

// *************************************************************************//

// NOTE:                                                                      

// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  

// which return objects that may need to be explicitly created via a function 

// call prior to any access via the property. These items have been disabled  

// in order to prevent accidental use from within the object inspector. You   

// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   

// removing them from the $IFDEF blocks. However, such items must still be    

// programmatically created via a method of the appropriate CoClass before    

// they can be used.                                                          

{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 

{$WARN SYMBOL_PLATFORM OFF}

{$WRITEABLECONST ON}

{$VARPROPSETTER ON}

interface

 

uses Windows, ActiveX, Classes, Graphics, mscorlib_TLB, OleServer, StdVCL, Variants;

  

 

 

// *********************************************************************//

// GUIDS declared in the TypeLibrary. Following prefixes are used:        

//   Type Libraries     : LIBID_xxxx                                      

//   CoClasses          : CLASS_xxxx                                      

//   DISPInterfaces     : DIID_xxxx                                       

//   Non-DISP interfaces: IID_xxxx                                        

// *********************************************************************//

const

  // TypeLibrary Major and minor versions

  System_DrawingMajorVersion = 2;

  System_DrawingMinorVersion = 0;

 

  LIBID_System_Drawing: TGUID = '{D37E2A3E-8545-3A39-9F4F-31827C9124AB}';

 

  IID__Image: TGUID = '{2948EBCD-5E0A-3184-9A87-37D3258C0D98}';

  IID__Bitmap: TGUID = '{F86086E0-A89E-3EBE-B036-79BF72354656}';

  IID__Font: TGUID = '{BC28F4B1-B9AB-3DD8-A471-5B7AE757F8F9}';

  CLASS_Image: TGUID = '{451DBF16-B46B-3B4F-993C-EFD8B01553A0}';

  CLASS_Bitmap: TGUID = '{6549E875-8857-35A3-94A2-C3D574DDEB1D}';

  CLASS_Font: TGUID = '{091B628B-3473-38BF-9A98-4F9DB4FB61F8}';

 

// *********************************************************************//

// Declaration of Enumerations defined in Type Library                    

// *********************************************************************//

// Constants for enum CopyPixelOperation

type

  CopyPixelOperation = TOleEnum;

const

  CopyPixelOperation_Blackness = $00000042;

  CopyPixelOperation_CaptureBlt = $40000000;

  CopyPixelOperation_DestinationInvert = $00550009;

  CopyPixelOperation_MergeCopy = $00C000CA;

  CopyPixelOperation_MergePaint = $00BB0226;

  CopyPixelOperation_NoMirrorBitmap = $80000000;

  CopyPixelOperation_NotSourceCopy = $00330008;

  CopyPixelOperation_NotSourceErase = $001100A6;

  CopyPixelOperation_PatCopy = $00F00021;

  CopyPixelOperation_PatInvert = $005A0049;

  CopyPixelOperation_PatPaint = $00FB0A09;

  CopyPixelOperation_SourceAnd = $008800C6;

  CopyPixelOperation_SourceCopy = $00CC0020;

  CopyPixelOperation_SourceErase = $00440328;

  CopyPixelOperation_SourceInvert = $00660046;

  CopyPixelOperation_SourcePaint = $00EE0086;

  CopyPixelOperation_Whiteness = $00FF0062;

 

type

 

// *********************************************************************//

// Forward declaration of types defined in TypeLibrary                    

// *********************************************************************//

  _Image = interface;

  _ImageDisp = dispinterface;

  _Bitmap = interface;

  _BitmapDisp = dispinterface;

  _Font = interface;

  _FontDisp = dispinterface;

 

// *********************************************************************//

// Declaration of CoClasses defined in Type Library                       

// (NOTE: Here we map each CoClass to its Default Interface)              

// *********************************************************************//

  Image = _Image;

  Bitmap = _Bitmap;

  Font = _Font;

 

 

// *********************************************************************//

// Declaration of structures, unions and aliases.                         

// *********************************************************************//

  Point = packed record

    x: Integer;

    y: Integer;

  end;

 

  Rectangle = packed record

    x: Integer;

    y: Integer;

    width: Integer;

    height: Integer;

  end;

 

  Size = packed record

    width: Integer;

    height: Integer;

  end;

 

  PointF = packed record

    x: Single;

    y: Single;

  end;

 

  SizeF = packed record

    width: Single;

    height: Single;

  end;

 

 

// *********************************************************************//

// Interface: _Image

// Flags:     (4432) Hidden Dual OleAutomation Dispatchable

// GUID:      {2948EBCD-5E0A-3184-9A87-37D3258C0D98}

// *********************************************************************//

  _Image = interface(IDispatch)

    ['{2948EBCD-5E0A-3184-9A87-37D3258C0D98}']

  end;

 

// *********************************************************************//

// DispIntf:  _ImageDisp

// Flags:     (4432) Hidden Dual OleAutomation Dispatchable

// GUID:      {2948EBCD-5E0A-3184-9A87-37D3258C0D98}

// *********************************************************************//

  _ImageDisp = dispinterface

    ['{2948EBCD-5E0A-3184-9A87-37D3258C0D98}']

  end;

 

// *********************************************************************//

// Interface: _Bitmap

// Flags:     (4432) Hidden Dual OleAutomation Dispatchable

// GUID:      {F86086E0-A89E-3EBE-B036-79BF72354656}

// *********************************************************************//

  _Bitmap = interface(IDispatch)

    ['{F86086E0-A89E-3EBE-B036-79BF72354656}']

  end;

 

// *********************************************************************//

// DispIntf:  _BitmapDisp

// Flags:     (4432) Hidden Dual OleAutomation Dispatchable

// GUID:      {F86086E0-A89E-3EBE-B036-79BF72354656}

// *********************************************************************//

  _BitmapDisp = dispinterface

    ['{F86086E0-A89E-3EBE-B036-79BF72354656}']

  end;

 

// *********************************************************************//

// Interface: _Font

// Flags:     (4432) Hidden Dual OleAutomation Dispatchable

// GUID:      {BC28F4B1-B9AB-3DD8-A471-5B7AE757F8F9}

// *********************************************************************//

  _Font = interface(IDispatch)

    ['{BC28F4B1-B9AB-3DD8-A471-5B7AE757F8F9}']

  end;

 

// *********************************************************************//

// DispIntf:  _FontDisp

// Flags:     (4432) Hidden Dual OleAutomation Dispatchable

// GUID:      {BC28F4B1-B9AB-3DD8-A471-5B7AE757F8F9}

// *********************************************************************//

  _FontDisp = dispinterface

    ['{BC28F4B1-B9AB-3DD8-A471-5B7AE757F8F9}']

  end;

 

// *********************************************************************//

// The Class CoImage provides a Create and CreateRemote method to          

// create instances of the default interface _Image exposed by              

// the CoClass Image. The functions are intended to be used by             

// clients wishing to automate the CoClass objects exposed by the         

// server of this typelibrary.                                            

// *********************************************************************//

  CoImage = class

    class function Create: _Image;

    class function CreateRemote(const MachineName: string): _Image;

  end;

 

// *********************************************************************//

// The Class CoBitmap provides a Create and CreateRemote method to          

// create instances of the default interface _Bitmap exposed by              

// the CoClass Bitmap. The functions are intended to be used by             

// clients wishing to automate the CoClass objects exposed by the         

// server of this typelibrary.                                            

// *********************************************************************//

  CoBitmap = class

    class function Create: _Bitmap;

    class function CreateRemote(const MachineName: string): _Bitmap;

  end;

 

// *********************************************************************//

// The Class CoFont provides a Create and CreateRemote method to          

// create instances of the default interface _Font exposed by              

// the CoClass Font. The functions are intended to be used by             

// clients wishing to automate the CoClass objects exposed by the         

// server of this typelibrary.                                            

// *********************************************************************//

  CoFont = class

    class function Create: _Font;

    class function CreateRemote(const MachineName: string): _Font;

  end;

 

implementation

 

uses ComObj;

 

class function CoImage.Create: _Image;

begin

  Result := CreateComObject(CLASS_Image) as _Image;

end;

 

class function CoImage.CreateRemote(const MachineName: string): _Image;

begin

  Result := CreateRemoteComObject(MachineName, CLASS_Image) as _Image;

end;

 

class function CoBitmap.Create: _Bitmap;

begin

  Result := CreateComObject(CLASS_Bitmap) as _Bitmap;

end;

 

class function CoBitmap.CreateRemote(const MachineName: string): _Bitmap;

begin

  Result := CreateRemoteComObject(MachineName, CLASS_Bitmap) as _Bitmap;

end;

 

class function CoFont.Create: _Font;

begin

  Result := CreateComObject(CLASS_Font) as _Font;

end;

 

class function CoFont.CreateRemote(const MachineName: string): _Font;

begin

  Result := CreateRemoteComObject(MachineName, CLASS_Font) as _Font;

end;

 

end.

Open in new window

0
Comment
Question by:matt_agm
  • 4
  • 3
7 Comments
 
LVL 21

Expert Comment

by:developmentguru
ID: 24029871
In order to get the type library definitions imported for the Image and Bitmap objects you will need to import the type library for System.Drawing.dll (and be sure you get the right version - I have a version 1a  and a version 2.0).  You can do this by going to the Component | Import Component menu, selecting to import it for Delphi if needed, then Import a Type Library and choose the System.Drawing.dll of the version you need.

Let me know if you need more.
0
 

Author Comment

by:matt_agm
ID: 24037756
Hi Thanks, I have imported the System.Drawing.dll version 2. this has placed three components on the tool pallet. However there are no direct image functions to access the image itself, is this possible? I was looking for something like SaveToFile or a function to copy the image to a VCL TImage
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 24038448
I took the source you provided and followed the GUID's through the registry to find out where to do the import.  My apologies that it did not get you what you were looking for.  I went to MSDN and looked up some information.  This should help.  I have a link to the Image properties and methods here:
http://msdn.microsoft.com/en-us/library/system.drawing.image_members.aspx

and here is a link to the bitmap class properties and methods:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap_members.aspx

both show a save method that will save to a file or stream.

There are many other classes listed in the system.drawing name space, here is a link.
http://msdn.microsoft.com/en-us/library/system.drawing.aspx

It looks like you may have to import your definition from the .NET dll directly (using the .NET code from your win32 application).  Microsoft is trying to push us all to .NET programming.  I will continue to dig on my end and see if I can find more.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 21

Expert Comment

by:developmentguru
ID: 24038713
If you go through the import of a .NET assembly you can click add and browse to c:\windows\Microsoft.NET\Framework\v2.0.50727\system.drawing.dll and import it for use in your Delphi application.  This gives you the same import you had before though, no methods.

One way I have accomplished this in the past is to us Delphi 2007 (.NET) to create a COM object that would expose the methods I needed.  Then I was able to use the COM object from my win32 code.  In your case you could expose a SaveToFile method that you create in your COM object which would in turn make the call through .NET.

I wish I had a more elegant solution for you.  This is the aftermath of Microshaft trying to grab us all by the back of the neck and force us to do things their way.  What do you think this is... Burger King?

I hope you don't take my attempts at humor the wrong way, just trying to lighten an ugly situation.
0
 

Author Comment

by:matt_agm
ID: 24039172
Thanks for you help, My experience with .Net is very minimal. So using Delphi.Net could I create a unit/function that could pass a _Image object with a filename and the .net code saves this file, would this work you think? Is there much involved with this or is it straight forward, thanks again for your help

Cheers
0
 
LVL 21

Accepted Solution

by:
developmentguru earned 500 total points
ID: 24051759
Using Delphi.NET I would create a COM object that wrappers your communication with the original .NET control.  At that point all of the communication is in .NET so there will be no problem manipulating the results (save to file, etc).  You would initiate the call to the COM object something like this (pseudo code)

Create MyNewCOMObject

MeNewComObject.CheckStatus(FileNames : OLEString);

{the FileNames could then be used to gather the bitmaps or images}

within the CheckStatus call on your COM object you would 1) talk to the other object you were getting your bitmap and image results from and 2) save them to files so they can be read by your win32 code.
0
 

Author Closing Comment

by:matt_agm
ID: 31564476
Thanks I have created a COM wrapper and it works great saving to a file to transfer into Delphi. This should probably go into a new question but is there a way of transferring an image from .Net to Delphi using COM and bypassing a temporary file?

Thanks again

Matt
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

706 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

19 Experts available now in Live!

Get 1:1 Help Now