I am currently using BTS BioEngineering SDK (real-time EMG data acquisition device) for a lab project. According to its documentation, libraries (.dll) from this SDK were written in C# and can be used in C++ project by registering them with regasm.exe from .NET framework. Basic working sample projects were included in both languages.
What I would like to do: Create C++ project from scratch using these libraries in Visual Studio. Eventually, I would like to create a GUI with Qt to display data acquisition in real-time.
What works:
.dll
files are registered successfully with Assembly Registration Tool (Regasm.exe). Registration is done in Prebuild event in Visual Studio configurations..tlh
and.tli
filed are generated.- It build successfully without any error or warning
- Types and objects are recognized in the IDE
(eg. Definition of IPortCOMPtr is shown in Visual Studio as
C++ typedef _com_ptr_t<_com_IIID<bts_biodaq_core::IPortCOM, &__uuidof(bts_biodaq_core::IPortCOM)>> bts_biodaq_core:: IPortCOMPtr
)
Problem: I get an _com_error when running the program (Exit Code 3, Abort() is called) and I am not sure to understand why...
Here the code that causes the program to crash:
#include "stdafx.h"
#include <process.h>
#import "mscorlib.tlb" auto_rename
#import "bts.biodaq.drivers.tlb"
#import "bts.biodaq.core.tlb"
using namespace std;
using namespace mscorlib;
using namespace bts_biodaq_core;
using namespace bts_biodaq_drivers;
int _tmain(int argc, _TCHAR* argv[])
{
USES_CONVERSION;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
IPortCOMPtr ptrCOMPort(__uuidof(PortCOM)); // _com_error here
return 0;
}
Batch script (.cmd) execute in prebuild event that I used:
set REGASM_FOLDER="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\"
set IMPORT_NAME_1=bts.biodaq.drivers
set IMPORT_NAME_2=bts.biodaq.core
echo Libraries to register
echo %IMPORT_NAME_1%
echo %IMPORT_NAME_2%
echo --------
echo Registering BioDaq libraries %IMPORT_NAME_1%.dll and %IMPORT_NAME_2%.dll
%REGASM_FOLDER%RegAsm "%DEPENDENCIES_FOLDER%\%IMPORT_NAME_1%.dll" /tlb: "%DEPENDENCIES_FOLDER%\%IMPORT_NAME_1%.tlb"
%REGASM_FOLDER%RegAsm "%DEPENDENCIES_FOLDER%\%IMPORT_NAME_2%.dll" /tlb: "%DEPENDENCIES_FOLDER%\%IMPORT_NAME_2%.tlb"
echo Copying BioDaq type libraries %IMPORT_NAME_1%.tlb and %IMPORT_NAME_2%.tlb
call :FCOPY "%DEPENDENCIES_FOLDER%\mscorlib.tlb" "%SOURCE_FOLDER%"
call :FCOPY "%DEPENDENCIES_FOLDER%\%IMPORT_NAME_1%.tlb" "%SOURCE_FOLDER%"
call :FCOPY "%DEPENDENCIES_FOLDER%\%IMPORT_NAME_2%.tlb" "%SOURCE_FOLDER%"
goto END
Error message on execution:
Debug Error
Program: C:\Users\myname\source\repos\Test\Debug\Test.exe
abort() has been called
I'm totally new to C#, COM interface and Typed Librabry (.tlb) so the answer might be obvious for some of you. Any help would be greatly appreciate! I can add more codes or information if needed.
Thanks! :)