EugeneK 23 Posted 17 hours ago I'm using DDetours to intercept Windows functions for unit testing purposes, but don't know how to intercept UuidCreate function because its declaration is hidden in implementation section of System.SysUtils unit. Is there a way to do it? Share this post Link to post
Remy Lebeau 1601 Posted 15 hours ago (edited) UuidCreate() is a Win32 API function, not a Delphi function. If you can't reach Delphi's declaration, then just make your own declaration in your own code. There is only one physical function to detour (residing in rpcrt4.dll), it doesn't matter how many declarations there are to reach it. Edited 15 hours ago by Remy Lebeau Share this post Link to post
Vincent Parrett 842 Posted 5 hours ago Intercepting functions for unit testing is a terrible idea. A better option would be to create abstractions and a concrete implementation (ie actually calls UuidCreate), that abstraction can be easily mocked using Delphi Mocks or Spring4D for uinit tests. The same applies to code that relies on things like Now or NowUTC - e.g - https://github.com/VSoftTechnologies/VSoft.System.TimeProvider Share this post Link to post
Artem Razin 12 Posted 3 hours ago UuidCreate is exported from rpcrt4.dll: function UuidCreate(out guid: TGUID): Longint; stdcall; external 'rpcrt4.dll' name 'UuidCreate' delayed; However, for testing purposes, I would use a custom implementation that returns a predefined GUID. Share this post Link to post
dwrbudr 8 Posted 39 minutes ago (edited) function Detour_UuidCreate(out guid: TGUID): Longint; stdcall; begin guid := Default(TGUID); Result := 0; end; procedure TForm68.Button1Click(Sender: TObject); var myguid: TGUID; begin InterceptCreate('rpcrt4.dll', 'UuidCreate', @Detour_UuidCreate); CreateGUID(myguid); end; So the above code does not work? On my side it works if I put a breakpoint in Detour_UuidCreate Edited 34 minutes ago by dwrbudr Share this post Link to post