ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

my ole-com function arx don't work on Autocad 2025

1 REPLY 1
SOLVED
Reply
Message 1 of 2
sizy458
318 Views, 1 Reply

my ole-com function arx don't work on Autocad 2025

Hello,

If this is incomplete, please let me know.

I made an arx com and I can call from another program, it works fine.
On Autocad 2025 I get this error on my function -> Invoke which return 'exception' :

System.Runtime.InteropServices.SEHException: 'Un composant externe a levé une exception.'

 

NONE of my COM functions work, I can only launch autocad 2025

client cpp file :

 

 

CoInitialize(NULL);

//UUID AUTOCAD 2025
 CLSID clsid;


 clsid.Data1 = 0x363E5B47;
 clsid.Data2 = 0x885D;
 clsid.Data3 = 0x44C3;
 clsid.Data4[0] = 0x89;
 clsid.Data4[1] = 0xeb;
 clsid.Data4[2] = 0xa2;
 clsid.Data4[3] = 0xab;
 clsid.Data4[4] = 0x21;
 clsid.Data4[5] = 0x29;
 clsid.Data4[6] = 0xb5;
 clsid.Data4[7] = 0x7e;

 if(::GetActiveObject(clsid,NULL,&pUnk)==S_OK) // Is AutoCAD already open?
 {
   erreur("already2\n");
  // ...Yes so let's get our interface to the Object Model..
  pUnk->QueryInterface(__uuidof(IAcadApplication),(LPVOID*)&acadApp);
pUnk->Release();

 
 }
  else
 {
  erreur("new2\n");
  hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL, __uuidof(IAcadApplication), (void**) &acadApp);

  //acadApp->Visible=VARIANT_TRUE;
 }

  AttachCOM();
  
  
  
  
  bool AttachCOM()
{	
	bool r=false;
	iii=NULL;
	for (int i = 0 ; i<16;i++)
	{
		__try
		{
			__AttachCOM();
			
			r=true;
			break;
		}
		__except(1)
		{
		}
	}
	if (iii!=NULL)
	{
		
		arxObj.AttachDispatch(iii,FALSE);
	
		MessageFilter *in=new MessageFilter();
		HRESULT hr = CoRegisterMessageFilter(in,NULL);	
	}
	else
	{
		
		r=false;
	}
	return r;
}

class MessageFilter  : public IMessageFilter
{
	DWORD STDMETHODCALLTYPE RetryRejectedCall(

         HTASK hTaskCallee, DWORD dwTickCount, DWORD dwRejectType

       )

       {

         return 1000; // Retry in a second

       }
	 DWORD STDMETHODCALLTYPE HandleInComingCall(

         DWORD dwCallType, HTASK hTaskCaller,

         DWORD dwTickCount, LPINTERFACEINFO lpInterfaceInfo
       )

       {

         return 0; // SERVERCALL_ISHANDLED

       }
	 DWORD STDMETHODCALLTYPE MessagePending(

         HTASK hTaskCallee, DWORD dwTickCount, DWORD dwPendingType
       )

       {

         return 1; // PENDINGMSG_WAITNOPROCESS

       }
	   HRESULT STDMETHODCALLTYPE QueryInterface( 
                /* [in] */ REFIID riid,
				/* [iid_is][out] */ __RPC__deref_out void __RPC_FAR *__RPC_FAR *ppvObject)
	   {
		   return 0;
	   }

       ULONG STDMETHODCALLTYPE AddRef( void)
	   {
		   return 0;
	   }

       ULONG STDMETHODCALLTYPE Release( void)
	   {
		   return 0;
	   }
};


void __AttachCOM()
{

	iii = acadApp->GetInterfaceObject(L"servcom2025.iarxobj");
	erreur("After 2025");
	if (iii == NULL)
	{
		erreur("Pas de com installé");
	}
	else
		erreur("GetInterfaceObject trouvé");
}

 

 

 

.h file 

 

 

class Ciarxobj2025 : public COleDispatchDriver
{
public:
	Ciarxobj2025() {} // Calls COleDispatchDriver default constructor
	Ciarxobj2025(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
	Ciarxobj2025(const Ciarxobj2025& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

	// Attributes
public:

	// Operations
public:


	// Iiarxobj methods
public:
	void test458(long test1, long test2)
	{
		static BYTE parms[] = VTS_I4 VTS_I4;
		InvokeHelper(0x1, DISPATCH_METHOD, VT_EMPTY, nullptr, parms, test1, test2);
	}
	/*....
	....*/
}

 

 

 

.idl file :

 

 

// servcom1.idl : IDL source
//
// This file will be processed by the MIDL tool to
// produce the type library (servcom1.tlb) and marshalling code.

import "oaidl.idl"; 
import "ocidl.idl";
//import "acadi.idl";

[
	object,
	uuid(2BC4C716-450C-493E-BA45-D2ADAC980F3D),
	dual,
	nonextensible,
	helpstring("Iiarxobj Interface"),
	pointer_default(unique)
]
interface Iiarxobj : IDispatch{
	[id(1), helpstring("method test458")] HRESULT test458(LONG test1, LONG test2);
	/*...
	...*/
};
[	
	//uuid(06B7CCFD-1DA4-43CB-A49F-8F4E1F172E82),
	uuid(6CFF8A3B-3843-49B3-9B2F-F91E792E995A),
	version(1.0),
	helpstring("servcom1 1.0 Type Library")
]
library servcom1Lib
{
	importlib("stdole32.tlb");
	importlib("stdole2.tlb"); 
	//----- If the following import fails then it means that the type library 
	//----- is not on the system path you can fix the problem in two ways:
	//----- 1. Add it to the system wide PATH environment variable
	//----- 2. Add it to the executable file list in Developer Studio. You can do
	//----- this in using the Tools/Option menu and then choosing the 'Directories'
	//----- tab and finally typing the full path at the Executable files section.

	//----- Importing english is ok here. Autodesk doesn't localize this idl/tlb.
	//----- axdb16enu.tlb is guaranteed to be available in all locales.
	//----- If you want to provide localized typelib then you must import
	//----- localized tlb here.
	importlib("axdb18enu.tlb");
	[		
		uuid(7C547673-46F4-468D-8048-C70DD5741EAB),
		helpstring("iarxobj Class")
	]
	coclass iarxobj
	{
		[default] interface Iiarxobj;
	};
};



.rgs file:
HKCR
{
	servcom2025.iarxobj.1 = s 'iarxobj Class'
	{
		CLSID = s '{7C547673-46F4-468D-8048-C70DD5741EAB}'
	}
	servcom2025.iarxobj = s 'iarxobj Class'
	{
		CLSID = s '{7C547673-46F4-468D-8048-C70DD5741EAB}'
		CurVer = s 'servcom2025.iarxobj.1'
	}
	NoRemove CLSID
	{
		ForceRemove {7C547673-46F4-468D-8048-C70DD5741EAB} = s 'iarxobj Class'
		{
			ProgID = s 'servcom2025.iarxobj.1'
			VersionIndependentProgID = s 'servcom2025.iarxobj'
			ForceRemove 'Programmable'
			InprocServer32 = s '%MODULE%'
			{
				val ThreadingModel = s 'Apartment'
			}
			'TypeLib' = s '{6CFF8A3B-3843-49B3-9B2F-F91E792E995A}'
		}
	}
}

 

 

 

.rgs file :

 

 

 HKCR
{
	NoRemove AppID
	{
		'%APPID%' = s 'servcom1'
		'servcom1.arx'
		{
			val AppID = s '%APPID%'
		}
	}
}

 

 

 

.cpp file for register arx

 

 

//-----------------------------------------------------------------------------
//- servcom1.cpp : Initialization functions
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include <initguid.h>
#include "servcom1.h"
#include "servcom1_i.c"
#include "acadi_i.c"
#include "iarxobj.h"
//les uuid sont inutiliser dans la base de registre
//-----------------------------------------------------------------------------
class Cservcom1Module : public CAtlDllModuleT<Cservcom1Module> {

public :
	DECLARE_LIBID(LIBID_servcom1Lib)
#ifdef v2018

	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SERVCOM1, "{45B87C2A-3947-419B-8946-2D9B12CA354A}")
#else
#ifdef v2017

	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SERVCOM1, "{C8B1EB7F-95E2-4145-A846-62308A029FCB}") 
#else
#ifdef v2015
	
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SERVCOM1, "{3919592B-3BE3-4645-98C4-DE703864F170}")
#else
#ifdef v2013
	
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SERVCOM1, "{995057C8-68D5-427A-A2E7-68290086E1DD}")
#else
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SERVCOM1, "{0F51302A-4EA8-42F9-BCD8-E475AB28F186}")
#endif
#endif
#endif
#endif
} ;

Cservcom1Module _AtlModule ;

//-----------------------------------------------------------------------------
//- DLL Entry Point
extern "C"
BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) {
	//- Remove this if you use lpReserved
	UNREFERENCED_PARAMETER(lpReserved) ;

	if ( dwReason == DLL_PROCESS_ATTACH ) {
        _hdllInstance =hInstance ;
	} else if ( dwReason == DLL_PROCESS_DETACH ) {
	}
	return (_AtlModule.DllMain (dwReason, lpReserved)) ; 
}

//-----------------------------------------------------------------------------
//- Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow (void) {
	HRESULT hr =(_AtlModule.GetLockCount () == 0 ? S_OK : S_FALSE) ;
	return (hr) ;
}

//-----------------------------------------------------------------------------
//- Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
	return (_AtlModule.GetClassObject (rclsid, riid, ppv)) ;
}

//-----------------------------------------------------------------------------
//- DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer (void) {
	//- Registers object, typelib and all interfaces in typelib
	return (_AtlModule.RegisterServer (TRUE)) ;
}

//-----------------------------------------------------------------------------
//- DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer (void) {
	return (_AtlModule.UnregisterServer (TRUE)) ;
}

//-----------------------------------------------------------------------------
#ifndef _WIN64
#pragma comment(linker, "/EXPORT:DllCanUnloadNow=_DllCanUnloadNow@0,PRIVATE")
#pragma comment(linker, "/EXPORT:DllGetClassObject=_DllGetClassObject@12,PRIVATE")
#pragma comment(linker, "/EXPORT:DllRegisterServer=_DllRegisterServer@0,PRIVATE")
#pragma comment(linker, "/EXPORT:DllUnregisterServer=_DllUnregisterServer@0,PRIVATE")
#else
#pragma comment(linker, "/EXPORT:DllCanUnloadNow=DllCanUnloadNow,PRIVATE")
#pragma comment(linker, "/EXPORT:DllGetClassObject=DllGetClassObject,PRIVATE")
#pragma comment(linker, "/EXPORT:DllRegisterServer=DllRegisterServer,PRIVATE")
#pragma comment(linker, "/EXPORT:DllUnregisterServer=DllUnregisterServer,PRIVATE")
#endif

 

 

 

 

Help please

Thank.

1 REPLY 1
Message 2 of 2
daniel_cadext
in reply to: sizy458

Shouldn’t

axdb18enu.tlb

be:

axdb25enu.tlb

 

The caller is .Net? maybe that needs to change from framework to core?

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report