Invalid class string when using CreateDispatch
-
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
-
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
Do you need to pass the string as wide characters (Unicode)?
Best wishes, Hans
-
Do you need to pass the string as wide characters (Unicode)?
Best wishes, Hans
-
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
-
Which of these formats[^] are you using, and what is the exact content of your parameter?
The best things in life are not things.
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?
-
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?
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 useCLSIDFromString()
[^] 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.
-
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 useCLSIDFromString()
[^] 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.
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
-
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
-
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.
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
-
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
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.