Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Overwriting COM

Overwriting COM

Scheduled Pinned Locked Moved COM
questioncom
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, i appologise if this question has been asked be before but its got me stummped, i need to overwrite one of the function pointers in a COM interface, i dont have access to the COM source nor can i modify it, i simply need to overwrite the pointer, i keep getting access violations.?? Goes something like this. IInterface * MyInterface= MakeInterface(); unsigned * vTbl = ((unsigned**)MyInterface)[0]; vTbl[THE_FUNCTION_INDEX] = NewFunction; Hope that gives you the idea of what i want, kinda like hooking a COM interface, i have yet to find an easy/any soloution like simply overwriting the functions pointer.

    S R S 3 Replies Last reply
    0
    • L Lost User

      Hi, i appologise if this question has been asked be before but its got me stummped, i need to overwrite one of the function pointers in a COM interface, i dont have access to the COM source nor can i modify it, i simply need to overwrite the pointer, i keep getting access violations.?? Goes something like this. IInterface * MyInterface= MakeInterface(); unsigned * vTbl = ((unsigned**)MyInterface)[0]; vTbl[THE_FUNCTION_INDEX] = NewFunction; Hope that gives you the idea of what i want, kinda like hooking a COM interface, i have yet to find an easy/any soloution like simply overwriting the functions pointer.

      S Offline
      S Offline
      soptest
      wrote on last edited by
      #2

      Implement interface you want to overwright. 1. You can use ATL to implement Interface. 2. Or see this example:

      #include "stdafx.h"
      #include "windows.h"
      #import "testObj.dll"
      /*
      // testObj.idl : IDL source for testObj.dll

      import "oaidl.idl";
      import "ocidl.idl";
      [
      object,
      uuid(C795331D-0C56-11D6-A0FD-00B0D0C3D9BD),
      dual,
      helpstring("Itest Interface"),
      pointer_default(unique)
      ]
      interface Itest : IDispatch
      {
      [id(1), helpstring("method f")] HRESULT f();
      [id(2), helpstring("method In")] HRESULT In([in] BSTR wsIn);
      };

      [
      uuid(C7953311-0C56-11D6-A0FD-00B0D0C3D9BD),
      version(1.0),
      helpstring("testObj 1.0 Type Library")
      ]
      library TESTOBJLib
      {
      importlib("stdole32.tlb");
      importlib("stdole2.tlb");

      \[
      	uuid(C795331E-0C56-11D6-A0FD-00B0D0C3D9BD),
      	helpstring("test Class")
      \]
      coclass test
      {
      	\[default\] interface Itest;
      	interface Itest2;
      };
      

      };

      */

      #include "comdef.h"
      class MyNew: public ::TESTOBJLib::ItestPtr
      {
      public:
      MyNew()
      {
      ::CoInitialize(0);
      ::TESTOBJLib::ItestPtr p;
      (*((::TESTOBJLib::ItestPtr*)this)).CreateInstance(L"TestObj.test");

      }
      ~MyNew()
      {
      	this->Release();
      	::CoUninitialize();
      }
      
      HRESULT In( \_bstr\_t wsIn )
      {//call default function
      	(\*((::TESTOBJLib::ItestPtr\*)this))->In(wsIn);
      	return S\_OK;
      };
      
      HRESULT f()
      {//overwritten function
      	::OutputDebugString("this my function.");
      	return S\_OK;
      }
      

      };

      int main(int argc, char* argv[])
      {
      MyNew p;

      p.f();
      p.In("test");
      
      return 0;
      

      }

      soptest

      L 1 Reply Last reply
      0
      • S soptest

        Implement interface you want to overwright. 1. You can use ATL to implement Interface. 2. Or see this example:

        #include "stdafx.h"
        #include "windows.h"
        #import "testObj.dll"
        /*
        // testObj.idl : IDL source for testObj.dll

        import "oaidl.idl";
        import "ocidl.idl";
        [
        object,
        uuid(C795331D-0C56-11D6-A0FD-00B0D0C3D9BD),
        dual,
        helpstring("Itest Interface"),
        pointer_default(unique)
        ]
        interface Itest : IDispatch
        {
        [id(1), helpstring("method f")] HRESULT f();
        [id(2), helpstring("method In")] HRESULT In([in] BSTR wsIn);
        };

        [
        uuid(C7953311-0C56-11D6-A0FD-00B0D0C3D9BD),
        version(1.0),
        helpstring("testObj 1.0 Type Library")
        ]
        library TESTOBJLib
        {
        importlib("stdole32.tlb");
        importlib("stdole2.tlb");

        \[
        	uuid(C795331E-0C56-11D6-A0FD-00B0D0C3D9BD),
        	helpstring("test Class")
        \]
        coclass test
        {
        	\[default\] interface Itest;
        	interface Itest2;
        };
        

        };

        */

        #include "comdef.h"
        class MyNew: public ::TESTOBJLib::ItestPtr
        {
        public:
        MyNew()
        {
        ::CoInitialize(0);
        ::TESTOBJLib::ItestPtr p;
        (*((::TESTOBJLib::ItestPtr*)this)).CreateInstance(L"TestObj.test");

        }
        ~MyNew()
        {
        	this->Release();
        	::CoUninitialize();
        }
        
        HRESULT In( \_bstr\_t wsIn )
        {//call default function
        	(\*((::TESTOBJLib::ItestPtr\*)this))->In(wsIn);
        	return S\_OK;
        };
        
        HRESULT f()
        {//overwritten function
        	::OutputDebugString("this my function.");
        	return S\_OK;
        }
        

        };

        int main(int argc, char* argv[])
        {
        MyNew p;

        p.f();
        p.In("test");
        
        return 0;
        

        }

        soptest

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Ok forgive me, im not familiar "yet", with COM and ATL etc, but from what i can gather that would require implementing every method and making it call the base (default) method for all methods i want to keep, unfortunatly the interfaces are pretty big reaching into the hundreds of methods and implementing each method to call its base method would be very time consuming.

        1 Reply Last reply
        0
        • L Lost User

          Hi, i appologise if this question has been asked be before but its got me stummped, i need to overwrite one of the function pointers in a COM interface, i dont have access to the COM source nor can i modify it, i simply need to overwrite the pointer, i keep getting access violations.?? Goes something like this. IInterface * MyInterface= MakeInterface(); unsigned * vTbl = ((unsigned**)MyInterface)[0]; vTbl[THE_FUNCTION_INDEX] = NewFunction; Hope that gives you the idea of what i want, kinda like hooking a COM interface, i have yet to find an easy/any soloution like simply overwriting the functions pointer.

          R Offline
          R Offline
          Ramu Pulipati
          wrote on last edited by
          #4

          COM supports two kinds of object orientation over binary components with C++. They are Containment and Aggregation. Containment: This is traditional C++ wrapping up style where the new CoClass will implement the desired interface and internally use the Binary component to perform the operations. Aggregation: The new CoClass will delegate the implemented interafce requests to the binary component and any request to the CoClass from binary component will be delegated back. This is a kinda tricky thing and has got restrictions. Like, the component being aggregated should be an In-Proc Server and should support component aggregation. Advantage of Containment Over Aggregation: It doesnt have any restrictions. Advantage of Aggregation Over Containment: You dont have to implement all interface methods by youself in the component. You'll just delegate, this will be handy if interface has lot of methods. Check out COM books for further details. Thanks, Ramu

          1 Reply Last reply
          0
          • L Lost User

            Hi, i appologise if this question has been asked be before but its got me stummped, i need to overwrite one of the function pointers in a COM interface, i dont have access to the COM source nor can i modify it, i simply need to overwrite the pointer, i keep getting access violations.?? Goes something like this. IInterface * MyInterface= MakeInterface(); unsigned * vTbl = ((unsigned**)MyInterface)[0]; vTbl[THE_FUNCTION_INDEX] = NewFunction; Hope that gives you the idea of what i want, kinda like hooking a COM interface, i have yet to find an easy/any soloution like simply overwriting the functions pointer.

            S Offline
            S Offline
            Sam Hobbs
            wrote on last edited by
            #5

            You are probably German. I think only Germans use the word "overwrite" like this. In the past I have tried to explain that the correct English word probably is "override" but Germans insist they are correct and I am mistaken. Perhaps you really want to override the function pointer, and if so then perhaps you will get help if you state the problem that way.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups