C++ Managed to Unmanaged GUID code convert (Win32/No IDL please)

Fleµve Relentless.resærch.lab 81 Reputation points
2022-09-14T12:54:17.923+00:00

Hello,

I'm presently developing an Add-ins for Autodesk Inventor, don't worry it's a true question about DLL and I think that Microsoft community was perfect for the situation. The form was pretty easy to use for who use C++ CLR/C# Managed style. A simple derived class with a GUIDAttribute.

#include "pch.h"  
  
using namespace Inventor;  
using namespace System::Windows::Forms;  
  
namespace RelentlessInventorManaged  
{  
	[Guid("698291FE-27CF-4EDE-A68D-2CEFA7DF30C5")]  
	public ref class StandardAddInServer : public ApplicationAddInServer  
	{  
		private:  
			Inventor::Application^ m_inventorApplication;  
  
		public:  
			StandardAddInServer()  
			{  
			}  
			virtual void Activate(Inventor::ApplicationAddInSite^ addInSiteObject, bool firstTime)  
			{  
				m_inventorApplication = addInSiteObject->Application;  
				MessageBox::Show("C++ Managed Version","Activate");  
			}  
			virtual void Deactivate()  
			{  
				m_inventorApplication = nullptr;  
				MessageBox::Show("C++ Managed Version", "Desactivate");  
  
			}  
			virtual void ExecuteCommand(int commandID)  
			{  
			}  
			virtual property Object^ Automation  
			{  
				Object^ get()  
				{  
					return nullptr;  
				}  
			}  
	};  
}  
  

I know two thing about the c++ standard version of the plugins.

  1. One of the parent of IRxApplicationAddInServer was IUnknown. (QueryInterface, AddRef, Release)
  2. The Entry of the plugins was DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)

Now, what is the fastest way to create a DLL with a GUID without using IDL (who generate file for you)? or what is the equivalent of [Guid("698291FE-27CF-4EDE-A68D-2CEFA7DF30C5")] in c++ unmanaged?

Thanks.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,683 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 44,931 Reputation points
    2022-09-14T14:26:24.287+00:00

    All COM interfaces are ultimately derived from IUnknown and contain the QueryInterface, AddRef and Release methods.

    Following snippet will declare and define a GUID in unmanaged C++ -

    #define INITGUID  
    #include <guiddef.h>  
      
    //698291FE-27CF-4EDE-A68D-2CEFA7DF30C5  
    DEFINE_GUID(MyGuid, 0x698291FE, 0x27CF, 0x4EDE, 0xA6, 0x8D, 0x2C, 0xEF, 0XA7, 0xDF, 0x30, 0xC5);  
      
    

    In my opinion the fastest way to create an in-process COM Server (DLL) is to use ATL. The ATL wizards will handle the IDL file for you but you may need to manually specify any required GUIDs instead of the ones that are generated by the wizards. ATL handles all of the scaffolding code that is required by COM.

    Coding a COM Server manually can be time consuming and error prone if you have never done it before.


  2. Fleµve Relentless.resærch.lab 81 Reputation points
    2022-09-15T14:09:24.557+00:00

    SELF-ANSWERING (Weird politics)

    Thanks Everyone!

    I found a COM Bible https://progtutorials.tripod.com/COM.htm and after reading it (Section 3.1 @ Section 3.3). I decide to retake the experiment and I totally broke the SDK. And no need ATL, macro function, no registry entry was required and other stuff like this.

    241506-inventorlite.txt

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.