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. C / C++ / MFC
  4. Invalid class string when using CreateDispatch

Invalid class string when using CreateDispatch

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++questioncsharpcom
10 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.
  • U Offline
    U Offline
    User 2970611
    wrote on last edited by
    #1

    Hi I have a MFC C++ project that calls a C# COM dll, which is registered on my development machine. However, when I step through the code, and it reaches the CreateDespatch passing in the GUID as the parameter, it throws an error "Invalid class string". Trying to resolve this issue, I feel that I have reached a dead end, and in need of help. Typically this is caused by the dll not being registered, but it is and I can see in regedit! So, what is causing this problem? Can anyone please help me? Thanks

    H L 2 Replies Last reply
    0
    • U User 2970611

      Hi I have a MFC C++ project that calls a C# COM dll, which is registered on my development machine. However, when I step through the code, and it reaches the CreateDespatch passing in the GUID as the parameter, it throws an error "Invalid class string". Trying to resolve this issue, I feel that I have reached a dead end, and in need of help. Typically this is caused by the dll not being registered, but it is and I can see in regedit! So, what is causing this problem? Can anyone please help me? Thanks

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      Do you need to pass the string as wide characters (Unicode)?

      Best wishes, Hans


      [Hans Dietrich Software]

      B 1 Reply Last reply
      0
      • H Hans Dietrich

        Do you need to pass the string as wide characters (Unicode)?

        Best wishes, Hans


        [Hans Dietrich Software]

        B Offline
        B Offline
        barneyman
        wrote on last edited by
        #3

        CreateDispatch takes a CLSID GUID or a progid String so - you do have the following entry?

        HKCR\CLSID\{GUID}\InprocServer32

        as an aside, it's (IMO) significantly easier to use ATL smart pointers than all the hoop-jumping IDispatch imposes ...

        1 Reply Last reply
        0
        • U User 2970611

          Hi I have a MFC C++ project that calls a C# COM dll, which is registered on my development machine. However, when I step through the code, and it reaches the CreateDespatch passing in the GUID as the parameter, it throws an error "Invalid class string". Trying to resolve this issue, I feel that I have reached a dead end, and in need of help. Typically this is caused by the dll not being registered, but it is and I can see in regedit! So, what is causing this problem? Can anyone please help me? Thanks

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

          Which of these formats[^] are you using, and what is the exact content of your parameter?

          The best things in life are not things.

          U 1 Reply Last reply
          0
          • L Lost User

            Which of these formats[^] are you using, and what is the exact content of your parameter?

            The best things in life are not things.

            U Offline
            U Offline
            User 2970611
            wrote on last edited by
            #5

            Hi I think it would be easier if I show you the relevant code snippet to see if you can assist me: m_dispatch = new COLeDispatchDriver(); COleException comError; if (m_dispatch->CreateDispatch(_T("99AA66456-082d-5b87-0df-51705603gdbd"), &comError)) { //Do some stuff here } else { //trap error here } What I am seeing is that when it reaches the if condition it jumps to the else part an I see the error message "Invalid class string". From the examples I have seen I thought passing in the GUID in this way is correct. Is it?

            L 1 Reply Last reply
            0
            • U User 2970611

              Hi I think it would be easier if I show you the relevant code snippet to see if you can assist me: m_dispatch = new COLeDispatchDriver(); COleException comError; if (m_dispatch->CreateDispatch(_T("99AA66456-082d-5b87-0df-51705603gdbd"), &comError)) { //Do some stuff here } else { //trap error here } What I am seeing is that when it reaches the if condition it jumps to the else part an I see the error message "Invalid class string". From the examples I have seen I thought passing in the GUID in this way is correct. Is it?

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

              If you look again at the link I gave you, the first parameter (in your case) needs to be a REFCLSID when providing the GUID of a registered class, whereas you have provided a string. You can always use CLSIDFromString()[^] function to do the conversion for you. BTW when posting code snippets please use the <pre></pre> tags around it to ensure formatting is retained.

              The best things in life are not things.

              U 1 Reply Last reply
              0
              • L Lost User

                If you look again at the link I gave you, the first parameter (in your case) needs to be a REFCLSID when providing the GUID of a registered class, whereas you have provided a string. You can always use CLSIDFromString()[^] function to do the conversion for you. BTW when posting code snippets please use the <pre></pre> tags around it to ensure formatting is retained.

                The best things in life are not things.

                U Offline
                U Offline
                User 2970611
                wrote on last edited by
                #7

                Sorry, but I must be misunderstanding this because I am unclear what you mean. I searched for the dll in regedit and found the progid folder. Taking the name that was there along with the period for version 1 it was still throwing the same error. For instance my test dll I have called TestCSharp that has a class called Test. This is shown in the ProgId folder as TestCSharp.Test. I have placed this as the parameter with period 1. So, I could do with a little bit of helping hand here. Thanks

                L 1 Reply Last reply
                0
                • U User 2970611

                  Sorry, but I must be misunderstanding this because I am unclear what you mean. I searched for the dll in regedit and found the progid folder. Taking the name that was there along with the period for version 1 it was still throwing the same error. For instance my test dll I have called TestCSharp that has a class called Test. This is shown in the ProgId folder as TestCSharp.Test. I have placed this as the parameter with period 1. So, I could do with a little bit of helping hand here. Thanks

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

                  I have never used the program id, only GUIDs; try what I suggested as it should work.

                  The best things in life are not things.

                  U 1 Reply Last reply
                  0
                  • L Lost User

                    I have never used the program id, only GUIDs; try what I suggested as it should work.

                    The best things in life are not things.

                    U Offline
                    U Offline
                    User 2970611
                    wrote on last edited by
                    #9

                    Hi Sorry for not getting back to you, but I did use your solution and yes you are right it did work. Please excuse me but I am very new to C++!! However, I have hit another problem whilst I can call my C# COM object it throws an error it says "the file or assembly xxxxxx cannot be loaded or one of its dependencies. The file sepecified can be found". In my C# COM object I am referencing another class, which itself references another class. When I compiled the C# COM Object, the bin file has the other classes as dlls are present. What am I doing wrong here? I have to be careful here because the referenced referenced class is used elsewhere in the other project. So, I am not sure whether adding a strong key and registering it would break the program elsewhere. Can you help? Thanks

                    L 1 Reply Last reply
                    0
                    • U User 2970611

                      Hi Sorry for not getting back to you, but I did use your solution and yes you are right it did work. Please excuse me but I am very new to C++!! However, I have hit another problem whilst I can call my C# COM object it throws an error it says "the file or assembly xxxxxx cannot be loaded or one of its dependencies. The file sepecified can be found". In my C# COM object I am referencing another class, which itself references another class. When I compiled the C# COM Object, the bin file has the other classes as dlls are present. What am I doing wrong here? I have to be careful here because the referenced referenced class is used elsewhere in the other project. So, I am not sure whether adding a strong key and registering it would break the program elsewhere. Can you help? Thanks

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

                      I'm not sure what the issue is here, but it sounds like you have some files missing, or not installed in the correct directories for the Windows loader to find them when they are called. You may also like to consider trying to simplify the structure of your application if at all possible.

                      The best things in life are not things.

                      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