Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. use std::os::raw::c_void;
  2. type IUnknownVPtr = c_void;
  3.  
  4. struct BritishShortHairCat {
  5.  
  6. }
  7.  
  8. trait ComInterface {
  9. fn gen_vtable<T, P>();
  10. }
  11.  
  12. trait ICat {
  13.  
  14. }
  15.  
  16. impl ComInterface for dyn ICat {
  17. fn gen_vtable<T, P>() {
  18. macro_rules! icat_gen_vtable {
  19. ($generic:ty, $offset:ty) => {
  20. IAnimal::gen_vtable::<$generic, $offset>();
  21.  
  22. unsafe extern "stdcall" fn add_ref<T, P: Offset>(this: *mut IUnknownVPtr) {
  23. println!("Offset value: {}", P::value());
  24. let this = this.sub(P::value()) as *mut T;
  25. // (*this).add_ref();
  26. }
  27. }
  28. }
  29.  
  30. icat_gen_vtable!(T, P);
  31. }
  32. }
  33.  
  34. trait IAnimal {
  35.  
  36. }
  37.  
  38. impl ComInterface for dyn IAnimal {
  39. fn gen_vtable<T, P>() {
  40. macro_rules! ianimal_gen_vtable {
  41. ($generic:ty, $offset:ty) => {
  42.  
  43. }
  44. }
  45.  
  46. ianimal_gen_vtable!(T, P);
  47. }
  48. }
  49.  
  50. fn main() {
  51. ICat::gen_vtable::<BritishShortHairCat, ONE>();
  52. }
  53.  
  54. trait Offset {
  55. fn value() -> usize;
  56. }
  57.  
  58. struct ONE {}
  59.  
  60. impl Offset for ONE {
  61. fn value() -> usize {
  62. 1
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement