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. ATL / WTL / STL
  4. "Access Violation Error" Using Custom COM [modified]

"Access Violation Error" Using Custom COM [modified]

Scheduled Pinned Locked Moved ATL / WTL / STL
c++comwindows-admintoolshelp
10 Posts 3 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.
  • A Offline
    A Offline
    ajitatif angajetor
    wrote on last edited by
    #1

    hi everyone, i created a custom COM component (.exe) which is used by another .dll. i compiled the both components fine, including the code snippet below; but i get a runtime access violation error on line of exe->Dummy() after CoCreateInstance returns S_OK. it gives different addresses for each different method of the .exe component i try. this code is inside a method of the .dll component HRESULT hr = 0; ATLVERIFY(SUCCEEDED(CoInitialize(NULL))); ATL::CComPtr exe; hr = exe.CoCreateInstance(CLSID_Something,NULL,CLSCTX_LOCAL_SERVER); // call out for .exe component ATLASSERT(SUCCEEDED(hr) && exe != NULL); ATLVERIFY(SUCCEEDED(exe->Dummy())); // access violation here exe.Release(); // doesn't make it to here anyway My .exe component is non-attributed just like the .dll (not sure if it makes any difference), i have built and registered the proxy-stub class fine, and also my .exe file is registered with "exe /RegServer". i think there is one more thing to be done but just couldn't find out what. if it were the registry script or something, i shouldn't be getting an instance of the .exe component. any ideas ? please have some !! -- modified at 14:18 Thursday 22nd March, 2007 edit: i converted the .exe interface to be non-dual (it was a dual interface before) and this time exe->Dummy() returns "A null reference pointer was passed to the stub."

    R 1 Reply Last reply
    0
    • A ajitatif angajetor

      hi everyone, i created a custom COM component (.exe) which is used by another .dll. i compiled the both components fine, including the code snippet below; but i get a runtime access violation error on line of exe->Dummy() after CoCreateInstance returns S_OK. it gives different addresses for each different method of the .exe component i try. this code is inside a method of the .dll component HRESULT hr = 0; ATLVERIFY(SUCCEEDED(CoInitialize(NULL))); ATL::CComPtr exe; hr = exe.CoCreateInstance(CLSID_Something,NULL,CLSCTX_LOCAL_SERVER); // call out for .exe component ATLASSERT(SUCCEEDED(hr) && exe != NULL); ATLVERIFY(SUCCEEDED(exe->Dummy())); // access violation here exe.Release(); // doesn't make it to here anyway My .exe component is non-attributed just like the .dll (not sure if it makes any difference), i have built and registered the proxy-stub class fine, and also my .exe file is registered with "exe /RegServer". i think there is one more thing to be done but just couldn't find out what. if it were the registry script or something, i shouldn't be getting an instance of the .exe component. any ideas ? please have some !! -- modified at 14:18 Thursday 22nd March, 2007 edit: i converted the .exe interface to be non-dual (it was a dual interface before) and this time exe->Dummy() returns "A null reference pointer was passed to the stub."

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      CComPtr is a template and its argument is the interface it should contain, e.g. CComPtr<IDispatch>. It looks like you have omitted the interface UUID. It could be a posting error and that "<" and ">" were interpreted as HTML tags. Have you tried using the DLL version as an inproc server? If you haven't, please do so and tell us what happens.


      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      A 1 Reply Last reply
      0
      • R Roger Stoltz

        CComPtr is a template and its argument is the interface it should contain, e.g. CComPtr<IDispatch>. It looks like you have omitted the interface UUID. It could be a posting error and that "<" and ">" were interpreted as HTML tags. Have you tried using the DLL version as an inproc server? If you haven't, please do so and tell us what happens.


        "It's supposed to be hard, otherwise anybody could do it!" - selfquote
        "High speed never compensates for wrong direction!" - unknown

        A Offline
        A Offline
        ajitatif angajetor
        wrote on last edited by
        #3

        i created another project whose proxy-stub is merged and now the problem is resolved into another one: i use HKEY in some of the functions as in and out parameters (they use registry keys), and my IDL file thinks HKEY is void *, contrary to the caller class, which sees HKEY as struct HKEY__* (as it should). i think this causing inconsistency between the client and the server, since i get "bad variable type" (or something similar) from CoCreateInstance only when there is a method with a parameter typed HKEY in the server. i tried redeclaring HKEY in IDL file,including winnt.h but no luck. any hope here?

        R 1 Reply Last reply
        0
        • A ajitatif angajetor

          i created another project whose proxy-stub is merged and now the problem is resolved into another one: i use HKEY in some of the functions as in and out parameters (they use registry keys), and my IDL file thinks HKEY is void *, contrary to the caller class, which sees HKEY as struct HKEY__* (as it should). i think this causing inconsistency between the client and the server, since i get "bad variable type" (or something similar) from CoCreateInstance only when there is a method with a parameter typed HKEY in the server. i tried redeclaring HKEY in IDL file,including winnt.h but no luck. any hope here?

          R Offline
          R Offline
          Roger Stoltz
          wrote on last edited by
          #4

          I'm confused about what you're doing. If you're doing what I think you are, in my opinion you've complicated things more than necessary. In your first post you said that the interface was originally a dual interface. This means that it inherits from IDispatch, but a client would have the ability to call the interface methods through vtable calls. There are two major benefits from using an interface that inherits from IDispatch: (a) a wide variaty of clients can use it such as IE and (b) you can rely on typelib marshalling so you don't have to distribute your own proxy-stub DLL. Both (a) and (b) requires that your interface is automation compatible, i.e. the oleautomation attribute is added to the interface declaration in the IDL file. This also implies that you can only use data type that conforms to automation, i.e. data types that can be represented by a VARIANT. A HKEY cannot be represented in a VARIANT, thus you cannot use it; it won't even make it through the MIDL compiler. Another thing that bothers me is more a design issue. Originally you're creating a out-of-process server. Why would you open a registry key in one process and simply hand it over to another process? I have no idea what the server should do with the registry key, but I suggest that whatever it is it should be given a path where the modifications should be done and open the registry solely. Suppose that the exe-server is distributed to another machine, then it wouldn't even be the same registry. So I guess it's about two questions: 1. What is the server supposed to do with the registry? 2. What are the limitations of the server in the aspect of automation and distribution?


          "It's supposed to be hard, otherwise anybody could do it!" - selfquote
          "High speed never compensates for wrong direction!" - unknown

          A 1 Reply Last reply
          0
          • R Roger Stoltz

            I'm confused about what you're doing. If you're doing what I think you are, in my opinion you've complicated things more than necessary. In your first post you said that the interface was originally a dual interface. This means that it inherits from IDispatch, but a client would have the ability to call the interface methods through vtable calls. There are two major benefits from using an interface that inherits from IDispatch: (a) a wide variaty of clients can use it such as IE and (b) you can rely on typelib marshalling so you don't have to distribute your own proxy-stub DLL. Both (a) and (b) requires that your interface is automation compatible, i.e. the oleautomation attribute is added to the interface declaration in the IDL file. This also implies that you can only use data type that conforms to automation, i.e. data types that can be represented by a VARIANT. A HKEY cannot be represented in a VARIANT, thus you cannot use it; it won't even make it through the MIDL compiler. Another thing that bothers me is more a design issue. Originally you're creating a out-of-process server. Why would you open a registry key in one process and simply hand it over to another process? I have no idea what the server should do with the registry key, but I suggest that whatever it is it should be given a path where the modifications should be done and open the registry solely. Suppose that the exe-server is distributed to another machine, then it wouldn't even be the same registry. So I guess it's about two questions: 1. What is the server supposed to do with the registry? 2. What are the limitations of the server in the aspect of automation and distribution?


            "It's supposed to be hard, otherwise anybody could do it!" - selfquote
            "High speed never compensates for wrong direction!" - unknown

            A Offline
            A Offline
            ajitatif angajetor
            wrote on last edited by
            #5

            i'm trying to create a broker process for an internet explorer toolbar to work on windows vista. internet explorer (only in vista) puts the toolbar on low registry profile on most of the web pages (all except those in trusted zone), which gets things complicated. you open a trusted site and toolbar tries to read from HKCU, you open another site and it tries to read from HKLM\Software\Microsoft\InternetExplorer\LowRegistry... something. so what i'm doing is to use an executable file (which will always work on low profile) to do the trick. toolbar just says "save the setting", and turn away. executable will always save these settings to the LowRegistry key. this is what i understood on msdn articles, did i simply misunderstood them?

            R L 2 Replies Last reply
            0
            • A ajitatif angajetor

              i'm trying to create a broker process for an internet explorer toolbar to work on windows vista. internet explorer (only in vista) puts the toolbar on low registry profile on most of the web pages (all except those in trusted zone), which gets things complicated. you open a trusted site and toolbar tries to read from HKCU, you open another site and it tries to read from HKLM\Software\Microsoft\InternetExplorer\LowRegistry... something. so what i'm doing is to use an executable file (which will always work on low profile) to do the trick. toolbar just says "save the setting", and turn away. executable will always save these settings to the LowRegistry key. this is what i understood on msdn articles, did i simply misunderstood them?

              R Offline
              R Offline
              Roger Stoltz
              wrote on last edited by
              #6

              I don't get why the server has to be an out-of-process server. Do you have any links to the articles that describe this?


              "It's supposed to be hard, otherwise anybody could do it!" - selfquote
              "High speed never compensates for wrong direction!" - unknown

              A 1 Reply Last reply
              0
              • R Roger Stoltz

                I don't get why the server has to be an out-of-process server. Do you have any links to the articles that describe this?


                "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                "High speed never compensates for wrong direction!" - unknown

                A Offline
                A Offline
                ajitatif angajetor
                wrote on last edited by
                #7

                sure, here it is http://msdn.micro­soft.com/library/en-us/ietechcol/dnwebgen/protectedmode.asp

                1 Reply Last reply
                0
                • A ajitatif angajetor

                  i'm trying to create a broker process for an internet explorer toolbar to work on windows vista. internet explorer (only in vista) puts the toolbar on low registry profile on most of the web pages (all except those in trusted zone), which gets things complicated. you open a trusted site and toolbar tries to read from HKCU, you open another site and it tries to read from HKLM\Software\Microsoft\InternetExplorer\LowRegistry... something. so what i'm doing is to use an executable file (which will always work on low profile) to do the trick. toolbar just says "save the setting", and turn away. executable will always save these settings to the LowRegistry key. this is what i understood on msdn articles, did i simply misunderstood them?

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  ajitatif angajetor wrote:

                  did i simply misunderstood them?

                  Maybe. The article seems to say that depending on the IL the process "write" operations are restricted. However the lowest IL level has write access to HKEY_CURRENT_USER\Software\LowRegistry key so I would believe all higher IL's would as well. It seems that is what you need write access for (based on your post) and therefore you do NOT need a broker process with elevated IL access... if I understand your posts correctly.

                  led mike

                  A 1 Reply Last reply
                  0
                  • L led mike

                    ajitatif angajetor wrote:

                    did i simply misunderstood them?

                    Maybe. The article seems to say that depending on the IL the process "write" operations are restricted. However the lowest IL level has write access to HKEY_CURRENT_USER\Software\LowRegistry key so I would believe all higher IL's would as well. It seems that is what you need write access for (based on your post) and therefore you do NOT need a broker process with elevated IL access... if I understand your posts correctly.

                    led mike

                    A Offline
                    A Offline
                    ajitatif angajetor
                    wrote on last edited by
                    #9

                    nice touch, but the moment you ask for HKEY_CURRENT_USER in a low integrity process, windows vista will give you the HKEY_CURRENT_USER\Software\LowRegistry key. so the low integrity process will read/write to a position like HKEY_CURRENT_USER\Software\LowRegistry\<user_id>\Software\LowRegistry

                    L 1 Reply Last reply
                    0
                    • A ajitatif angajetor

                      nice touch, but the moment you ask for HKEY_CURRENT_USER in a low integrity process, windows vista will give you the HKEY_CURRENT_USER\Software\LowRegistry key. so the low integrity process will read/write to a position like HKEY_CURRENT_USER\Software\LowRegistry\<user_id>\Software\LowRegistry

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #10

                      Ok but I don't understand why that is a problem.

                      led mike

                      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