1、
unit formMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Memo1: TMemo; edtDestHWnd: TEdit; Label1: TLabel; Button4: TButton; Button5: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); private public procedure TestParam(_i :integer; _f :single; _d :double; _pc :PChar; _pi :PInteger);stdcall; procedure Test(_i, _j :integer);stdcall; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var hWnd1 :HWND; begin hWnd1 := strtoint(‘$‘+trim(edtDestHWnd.Text)); PostMessage(hWnd1, WM_USER+1000, 0, 0); end; procedure TForm1.Button2Click(Sender: TObject); var hWnd1 :HWND; begin hWnd1 := strtoint(‘$‘+trim(edtDestHWnd.Text)); PostMessage(hWnd1, WM_USER+1001, 0, 0); end; procedure TForm1.Button3Click(Sender: TObject); var hWnd1 :HWND; begin hWnd1 := strtoint(‘$‘+trim(edtDestHWnd.Text)); SendMessage(hWnd1, WM_USER+1001, 0, 0); end; {$O-} procedure TForm1.Button4Click(Sender: TObject); var pc, pc1 :PChar; i, j :integer; str :string; iLow, iHigh :integer; d :double; f :single; begin pc := ‘ABC‘; j := integer(@i); str := inttohex(j, 8);//str: ‘0018F574‘ j := integer(pc); str := inttohex(j, 8);// str: ‘00403277‘ j := integer(@pc); str := inttohex(j, 8);// str: ‘00403277‘ d := 3.0; pc1 := PChar(@d); CopyMemory(@iLow, pc1, 4); CopyMemory(@iHigh, @pc1[4], 4); str := inttohex(iLow, 8); // 0 str := inttohex(iHigh, 8);// str: ‘40080000‘ f := 2.0; CopyMemory(@j, @f, 4); str := inttohex(j, 8);// str: ‘40000000‘ TestParam(1, 2.0, 3.0, pc, @i); end; {$O+} {$O-} procedure TForm1.Test(_i, _j: integer);stdcall; begin try _i := _i div _j; finally _i := 3; end; end; procedure TForm1.TestParam(_i: integer; _f: single; _d: double; _pc :PChar; _pi :PInteger);stdcall; begin end; {$O+} procedure TForm1.Button5Click(Sender: TObject); begin // Test(6, 3); Test(6, 0); end; end.
2、
#include <stdio.h> #include <windows.h> void __stdcall TestParam(int _i, float _f, double _d, char* _pc, int* _pi) { } void __stdcall Test(int _i, int _j) { //__try //{ _i = _i / _j; //} //__finally //{ // _i = 3; //} } void main() { __asm { mov eax,eax mov eax,eax mov eax,eax //int 3 } Test(6, 0); } //void main() //{ // char * pc = "ABC"; // printf("pc : %X\n", (int)pc); // // char *pc1 = NULL; // float f = 2.0; // double d = 3.0; // // DWORD dwLow = 0, dwHigh=0; // // pc1 = (char*)&f; // memcpy(&dwLow, pc1, 4); // printf("f : %X\n", dwLow); // // pc1 = (char*)&d; // memcpy(&dwLow, pc1, 4); // memcpy(&dwHigh, &pc1[4], 4); // printf("d[low] : %X\n", dwLow); // printf("d[high] : %X\n", dwHigh); // // int i = 6; // printf("&i : %X\n", (int)&i); // // TestParam(1, f, d, pc, &i); // //}
3、
4、
5、