Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:24:56+00:00 2026-06-01T20:24:56+00:00

i’ve this component that i want to use it in a DLL to achieve

  • 0

i’ve this component that i want to use it in a DLL to achieve a system-wide hook :

unit ClipboardHook;

interface

uses
  Windows, SysUtils, Classes, ExtCtrls;

type
 TFOnOpenClipboard = procedure(Sender:TObject; hWndNewOwner:HWND; 
   var opContinue:Boolean) of object;
 TFOnSetClipboardData = procedure(Sender:TObject; hWndNewOwner:HWND; 
   uFormat:DWord; hMem:THandle; var opContinue:Boolean) of object;

type
  TClipboardHook = class(TComponent)
  private
    { Private declarations }
    FOnOpenClipboard:TFOnOpenClipboard;
    FOnSetClipboardData:TFOnSetClipboardData;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    //------------------------------------------------
  published
    { Published declarations }
    property OnOpenClipboard:TFOnOpenClipboard 
      read FOnOpenClipboard write FOnOpenClipboard;
    property OnSetClipboardData:TFOnSetClipboardData 
      read FOnSetClipboardData write FOnSetClipboardData;
  end;

implementation

type
  TcOpen=function(hWndNewOwner:HWND):Bool; stdcall;

  TscData=function(uFormat:DWord; hMem:Thandle):THandle; stdcall;

  TOP_H = packed record
    Push:Byte;
    Address:DWord;
    Ret:Byte;
  end; 

var 
  OC_Addr,SCD_Addr:Pointer;
  OP:DWord;
  cOpen,rcOpen,scData,rscData:TOP_H;
  WPM:DWord;
  sComponent:TObject;

{***************************Start:TClipboardHook***************************}
function Open_Clipboard(hWndNewOwner:HWND):Bool; stdcall;
var 
  c: Boolean;
begin
  c:=true;
  if Assigned(TClipboardHook(sComponent).FOnOpenClipboard) then
    TClipboardHook(sComponent).FOnOpenClipboard(sComponent,hWndNewOwner,c);
  if c then
  begin
    WriteProcessMemory(OP,OC_Addr,@rcOpen,SizeOf(rcOpen),WPM);
    Result:=TcOpen(OC_Addr)(hWndNewOwner);
    WriteProcessMemory(OP,OC_Addr,@cOpen,SizeOf(cOpen),WPM);
  end 
  else 
    Result:=false;
end;

function Set_ClipboardData(uFormat:DWord; hMem:THandle):THandle; stdcall;
var 
  c: Boolean;
  Win: DWord;
begin         
  c := true;
  Win := GetOpenClipboardWindow();
 if (Win <> 0) and 
    (Assigned(TClipboardHook(sComponent).FOnSetClipboardData)) then
   TClipboardHook(sComponent).FOnSetClipboardData(sComponent,Win,uFormat,hMem,c);
 if c then
 begin
   WriteProcessMemory(OP,SCD_Addr,@rscData,SizeOf(rscData),WPM);
   Result:=TscData(SCD_Addr)(uFormat,hMem);
   WriteProcessMemory(OP,SCD_Addr,@scData,SizeOf(scData),WPM);
 end 
 else 
   Result:=0;
end;

{****************************End:TClipboardHook****************************}
{##############################################################################}
constructor TClipboardHook.Create(AOwner:TComponent);
var 
  Dll: DWord;
begin
  inherited Create(Aowner);
  if (csDesigning in ComponentState) then 
    exit;
  sComponent:=Self;
  DLL := LoadLibrary('user32.dll');
  if DLL <> 0 then
  begin
    OC_Addr := GetProcAddress(DLL,'OpenClipboard');
    SCD_Addr := GetProcAddress(DLL,'SetClipboardData');
    if (OC_Addr <> nil) or (SCD_Addr <> nil) then
    begin      
      OP:=OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessID);
      if OP <> 0 then
      begin
        if OC_Addr <> nil then
        begin
          cOpen.Push := $68;
          cOpen.Address := DWord(@Open_Clipboard);
          cOpen.Ret := $C3;
          ReadProcessMemory(OP, OC_Addr, @rcOpen, SizeOf(rcOpen), WPM);
          WriteProcessMemory(OP, OC_Addr, @cOpen, SizeOf(cOpen), WPM);
        end;
        if SCD_Addr <> nil then
        begin
          scData.Push := $68;
          scData.Address := DWord(@Set_ClipboardData);
          scData.Ret := $C3;
          ReadProcessMemory(OP, SCD_Addr, @rscData, SizeOf(rscData), WPM);
          WriteProcessMemory(OP, SCD_Addr, @scData, SizeOf(scData), WPM);
        end;
      end;
    end;
   FreeLibrary(Dll);
  end;
end;

destructor TClipboardHook.destroy;
begin
 if (OC_Addr <> nil) then 
   WriteProcessMemory(OP, OC_Addr, @rcOpen, SizeOf(rcOpen), WPM);
 if OP <> 0 then CloseHandle(OP);
 inherited destroy;
end;

{##############################################################################}
end.

can someone help me in putting all these stuffs into a DLL ( without the Component ) ,i mean only the functions .

many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:24:57+00:00Added an answer on June 1, 2026 at 8:24 pm

    You can export functions simply by including an exports clause somewhere in your unit. To export the two functions in that code, add this at the bottom of your unit:

    exports
      Open_Clipboard,
      Set_ClipboardData;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.