Calling functions in a DLL from an extension
I'm using TC8.1, have created an extension, and am now trying to call functions in a DLL from the extension code.
Initially we were adding the DLL to the CLRBridge of our main project (not the extension) and were using the dotNET object to call the functions in the dll. That seemed to work.
Now we are using extensions and need to call the DLL from the extension code too. Actually, since some of the extension code needs to call the DLL, I've moved everything that needs the DLL into the extension. Now I am having problems calling the DLL functions.
I originally tried adding the DLL to the extension's CLRBridge, and it did seem to work...sort of. It does not make sense to me that it should work at all since the tcx file for the extension only includes code files and the description.xml, so where would the CLRBridge info be included?
I did read that there is a way to go around the CLRBridge by using AppDomain. However, it is not well documented (at least as far as whether it can be used with DLL's as opposed to exe's)...so I gave up trying that.
I found another set of docs about calling functions in DLL's. It's complicated. You have to even prototype the functions that you want to call in the DLL, and you have to be careful about clearly specifying the types of parameters being passed. It seems to be like setting up the COM connections back in C++. I seem to have gotten through it but when I actually call a DLL function I get an exception "Object doesn't support this property or method."
It does not matter whether I call a function that has no parameters or a function that has parameters.
function Test_Misc()
{
var function_name = "reportservice_util_unit_test.Test_Misc";
var dll_path_name = "D:\\sandbox-v3-CopyLog\\Utilities\\LogGenerator.dll";
var dll_nickname = "LogGenerator";
var dll_environment = null; // Def_Environment in docs.
var dll_type = null; // Def_DLL in docs.
var dll_object = null; // Lib in docs.
try
{
//##########################################################################
// Define an environment (32-bit or 64-bit) for loading the DLL into.
// In this case it should go into the 32-bit environment automatically since the DLL is 32-bit.
//##########################################################################
dll_environment = DLL.DefineEnvironmentByDLL( dll_path_name );
if( dll_environment == null )
{
HelperForUnitTesting_TestFailed( function_name, "Unable to create an DLL Environment for [" + dll_path_name + "]." );
return false;
}
//##########################################################################
// Get a helper object to use in defining the type of routines in the DLL.
//##########################################################################
dll_type = dll_environment.DefineDLL( dll_nickname );
if( dll_type == null )
{
HelperForUnitTesting_TestFailed( function_name, "Unable to create an DLL Type for [" + dll_path_name + "]." );
return false;
}
//##########################################################################
// Define the functions to expect in the DLL.
// NOTE that first parameter is the FUNCTION_NAME.
// NOTE that final parameter is the FUNCTION_RETURN_TYPE (use vt_empty or vt_void if no return value).
//##########################################################################
// No parameters.
dll_type.DefineProc( "AppendEmptyLog", vt_void );
// Parameter1: ProjectName
// Parameter2: Machinename
dll_type.DefineProc( "CreateDateFolder", vt_lpstr, vt_lpstr, vt_void );
//##########################################################################
//##########################################################################
dll_object = dll_environment.Load( dll_path_name, dll_nickname );
if( dll_object == null )
{
HelperForUnitTesting_TestFailed( function_name, "Unable to create an DLL Object for [" + dll_path_name + "]." );
return false;
}
// Try a routine that has no parameters.
dll_object.AppendEmptyLog();
// Try a routine that has parameters.
var project_name = dll_environment.New( "LPSTR", 256 );
var machine_name = dll_environment.New( "LPSTR", 256 );
project_name.Text = "TestingDLL";
machine_name.Text = "ABCD";
dll_object.CreateDateFolder( project_name, machine_name );
}
catch( exception )
{
HelperForUnitTesting_TestFailed( function_name, Messages_CreateMessageForException( exception ) );
return false;
}
HelperForUnitTesting_TestSucceeded( function_name );
return true;
}
I get the exception whether I call AppendEmptyLog() or CreateDateFolder().
Any help would be appreciated. Thanks.