testdll.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. { %target=win32,win64 }
  2. { %needlibrary }
  3. { %norun }
  4. { %neededafter }
  5. {
  6. Copyright (c) 1998 by Pierre Muller
  7. Win32 DLL test with threads.
  8. }
  9. library testdll;
  10. function GetModuleFileName(hModule:longint;lpszPath:pchar;cchPath:longint):longint;
  11. stdcall; external 'kernel32' name 'GetModuleFileNameA';
  12. procedure beep(ID:longint);
  13. stdcall; external 'user32' name 'MessageBeep';
  14. var
  15. teststr : string;
  16. var
  17. global_count : longint;
  18. threadvar
  19. thread_local_count : longint{ = 6};
  20. procedure P1(var s:string);export;
  21. var
  22. i : longint;
  23. p:array[0..255] of char;
  24. begin
  25. i:=length(s);
  26. getmodulefilename(Hinstance,@p,255);
  27. writeln('DLL: Hello, I''m DLL ',pchar(@p));
  28. writeln('DLL: S before is "',s,'"');
  29. s:='New value';
  30. end;
  31. procedure P2(x:longint);export;
  32. begin
  33. writeln('DLL: Argument X=',x);
  34. writeln('DLL: New teststr="',teststr,'"');
  35. inc(global_count);
  36. inc(thread_local_count);
  37. Writeln('DLL: Thread Id is ',GetCurrentThreadId);
  38. Writeln('DLL: Global count=',Global_count);
  39. Writeln('DLL: Thread local count=',thread_local_count);
  40. end;
  41. procedure P3(var t);export;
  42. var
  43. p : pointer;
  44. begin
  45. p:=Addr(T);
  46. p:=p;
  47. end;
  48. procedure P4(x1:pointer);export;
  49. begin
  50. Inc(x1);
  51. end;
  52. function GetTestStr : string; export;
  53. begin
  54. GetTestStr:=teststr;
  55. end;
  56. procedure MyDllHook(DllParma : PtrInt);
  57. begin
  58. Writeln('DLL: Thread Detach Hook called with DLLParam=',DllParam);
  59. Writeln('DLL: Thread Id is ',GetCurrentThreadId);
  60. end;
  61. procedure NewExit;
  62. begin
  63. beep(0);
  64. writeln('DLL: Exit from testdll');
  65. Writeln('DLL: Thread Id is ',GetCurrentThreadId);
  66. end;
  67. exports
  68. P1 index 1,
  69. P2 name 'Proc2',
  70. P3,
  71. GetTestStr,
  72. P4 resident,
  73. teststr name 'FPC_string';
  74. begin
  75. Dll_Thread_Detach_Hook:=@MyDllHook;
  76. Writeln('DLL: Startup Thread Id is ',GetCurrentThreadId);
  77. writeln('DLL: HInstance ',Hinstance,' PrevInst ',Hprevinst,' DLLReason ',DLLreason,' DLLParam ',DLLparam);
  78. teststr:='DLL init done';
  79. exitproc:=@newExit;
  80. end.