Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This answer applies to Delphi XE2 Update 2, I don't know if things have changed with Update 3. </p> <p>I started the Embarcadero thread. Starting up GDI+ from the host application isn't an option for me. So far everything is working from the DLL side without errors but nothing has been released to the outside world yet either. </p> <p>If you are able to modify your C host application, you may find the <a href="http://msdn.microsoft.com/en-us/library/ms534077%28v=vs.85%29.aspx" rel="nofollow">MSDN GdiplusStartup() documentation</a> useful. </p> <p>====</p> <h2>Using FireMonkey In a DLL Without Starting GDI+ In Host Application</h2> <p>Add this unit to your project:</p> <pre><code>unit InitFmxHack; interface procedure InitGDIP; // Call before using FMX. procedure FreeGDIP; // Call after using FMX. // NOTE: // InitGDIP() must be called before instantiating a FireMonkey form. // FreeGDIP() must be called after all FireMonkey forms are destroyed. // // InitGDIP/FreeGDIP can not be called from the initalization or finalization sections, // or any method called from these sections. // implementation uses System.SysUtils, Winapi.GDIPAPI, Winapi.GDIPOBJ, FMX.Types; var NeedToShutdownGDIPlus: Boolean; GDIPlusInput: TGDIPlusStartupInput; gdiplusToken: Cardinal; TempRgn: GpRegion; type TBitmapAccess = class(TBitmap); procedure InitGDIP; begin NeedToShutdownGDIPlus := False; case GdipCreateRegion(TempRgn) of Ok: GdipDeleteRegion(TempRgn); GdiplusNotInitialized: begin GDIPlusInput.GdiplusVersion := 1; GDIPlusInput.DebugEventCallback := nil; GDIPlusInput.SuppressBackgroundThread := False; GDIPlusInput.SuppressExternalCodecs := False; GdiplusStartup(GDIPlusToken, @GDIPlusInput, nil); NeedToShutdownGDIPlus := True; end; end; end; procedure FreeGDIP; begin // HACK: Need to forcibly release a GDI+ object held in a global variable. FreeAndNil(TBitmapAccess(GetMeasureBitmap).FCanvas); // These lines have been copied from Winapi.GDIPOBJ. I'm not 100% sure // if there needed but it's probably safer to include them as they are part of // the standard FireMonkey shutdown sequence. Similar code is also found in // the VGScene library. if Assigned(GenericSansSerifFontFamily) then FreeAndNil(GenericSansSerifFontFamily); if Assigned(GenericSerifFontFamily) then FreeAndNil(GenericSerifFontFamily); if Assigned(GenericMonospaceFontFamily) then FreeAndNil(GenericMonospaceFontFamily); if Assigned(GenericTypographicStringFormatBuffer) then FreeAndNil(GenericTypographicStringFormatBuffer); if Assigned(GenericDefaultStringFormatBuffer) then FreeAndNil(GenericDefaultStringFormatBuffer); // Finalise GDI+ here if needed... if NeedToShutdownGDIPlus then GdiplusShutdown(GDIPlusToken); end; end. </code></pre> <p>To use:</p> <pre><code>InitFmxHack.InitGDIP; // 1. Create form here. // 2. Use form. // 3. Destroy form. InitFmxHack.FreeGDIP; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload