olecall.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #ifdef AFX_OLE5_SEG
  12. #pragma code_seg(AFX_OLE5_SEG)
  13. #endif
  14. // Note: because of the nature of these functions, it is not possible
  15. // to create a 'C' or 'C++' version of them. These functions are used
  16. // for the lowest level of the OLE IDispatch implementation, and need
  17. // to be ported to each supported platform.
  18. extern "C" {
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Intel 386 version
  21. #ifdef _X86_
  22. __declspec(naked) void AFXAPI
  23. _AfxDispatchCall(AFX_PMSG /*pfn*/, void* /*pArgs*/, UINT /*nSizeArgs*/)
  24. {
  25. #if defined(__BORLANDC__)
  26. /*
  27. Note: This routine is specific to the Borland C++ 5.x
  28. Pointer-to-Member-Function (PFM) binary layout. By default, -Vmv is on
  29. (member pointers have no restrictions) and thus the layout in 32-bit apps
  30. is 12-bytes. If any of the other -Vm... switches are used, this routine
  31. may have to be modified to support a different size PMF. We recommend
  32. that -Vmv always be used.
  33. */
  34. __emit__(0x5A, // pop edx ; edx = return address
  35. 0x58, // pop eax ; eax = pfn (PMF addr)
  36. 0x59, // pop ecx ; (extra PMF dword #1)
  37. 0x59, // pop ecx ; (extra PMF dword #2)
  38. 0x59, // pop ecx ; ecx = pArgs
  39. 0x50, // push eax
  40. 0x8B,0x44,0x24,0x04, // mov eax,[esp+4] ; eax = nSizeArgs
  41. 0x03,0xC8, // add ecx,eax ; ecx += nSizeArgs (=scratch area)
  42. 0x89,0x19, // mov [ecx],ebx ; scratch[0] = ebx
  43. 0x89,0x51,0x04, // mov [ecx+4],edx ; scratch[1] = return address
  44. 0x8B,0xD8, // mov ebx,eax ; ebx = nSizeArgs (saved across call)
  45. 0x58, // pop eax
  46. 0x2B,0x0C,0x24, // sub ecx,[esp] ; ecx = pArgs (again)
  47. 0x8B,0xE1, // mov esp,ecx ; esp = pArgs (usually already correct)
  48. '\xFF',0xD0, // call eax ; call member function
  49. 0x03,0xE3, // add esp,ebx ; cleanup arguments
  50. 0x5B, // pop ebx ; restore ebx
  51. 0xC3 // ret ; esp[0] should = scratch[0] = return address
  52. );
  53. #else
  54. _asm
  55. {
  56. pop edx // edx = return address
  57. pop eax // eax = pfn
  58. pop ecx // ecx = pArgs
  59. add ecx,[esp] // ecx += nSizeArgs (=scratch area)
  60. mov [ecx],edx // scratch[0] = return address
  61. sub ecx,[esp] // ecx = pArgs (again)
  62. mov esp,ecx // esp = pArgs (usually already correct)
  63. pop ecx // ecx = this pointer (the CCmdTarget*)
  64. call eax // call member function
  65. ret // esp[0] should = scratch[0] = return address
  66. }
  67. #endif
  68. }
  69. #endif // _X86_
  70. /////////////////////////////////////////////////////////////////////////////
  71. // MIPS R4000 version
  72. #ifdef _MIPS_
  73. extern "C" void _asm(char *, ...);
  74. void AFXAPI
  75. _AfxDispatchCall(AFX_PMSG /*pfn*/, void* /*pArgs*/, UINT /*nSizeArgs*/)
  76. {
  77. _asm("addiu %sp,%a1,0x0"); // sp = pArgs
  78. _asm("addiu %t6,%a0,0x0"); // t6 = pfn (save it)
  79. _asm("lw %a0,0x0(%sp)"); // a0 = param0
  80. _asm("lw %a1,0x4(%sp)"); // a1 = param1
  81. _asm("lw %a2,0x8(%sp)"); // a2 = param2
  82. _asm("lw %a3,0xc(%sp)"); // a3 = param3
  83. _asm("j %t6"); // ip = pfn (jump to target function)
  84. }
  85. #endif // _MIPS_
  86. /////////////////////////////////////////////////////////////////////////////
  87. // DEC Alpha AXP version
  88. #ifdef _ALPHA_
  89. // Note: ALPHA version is in src\alpha\olecall_.s
  90. // The ALPHA compiler does not support inline assembly, so it
  91. // must be build separately with the ASAXP assembler.
  92. #endif // _ALPHA_
  93. } // end extern "C" block
  94. /////////////////////////////////////////////////////////////////////////////