Calling .NET assembly from Delphi/C++Builder












0















I tried to use the TBluetoothLE component in a multi-platform application. The code works fine on iOS. Needs some tweaking to work correctly on Android. But I am not able to make it work on Windows.



I looked during debugging at the source code on the Windows platform, and it seems to use the WinRT API. I know that writing (and testing) a generic component that works well on several platforms is not so easy. But I'm wondering if we can use the WinRT directly from the application without using the component provided by Embarcadero.



There are many working examples in C# that I tested on Windows. BluetoothLEExplorer is a very good application that show the use of WinRT to discover and communicate with BLE devices.



Delphi also provides interface files to use WinRT, but there is no sample application showing how to use it.



I would like to investigate a very simple example of calling a function inside a .NET assembly from C++Builder.



In C#, a simple example is to call FromBluetoothAddressAsync to find if a BLE device with a given address is connectable:



C# example in 3 lines of code:



1- create a Watcher to discover BLE devices



BluetoothLEAdvertisementWatcher advWatcher;
// then call its Received method
advWatcher.Received(some_callback_function_to_be_called_when_the_watcher_detect_adevice);
//the discovered BLE device address is saved in variable uint_t64 deviceAddr by the callback_function


2- get a BluetoothLEDevice object for the device using FromBluetoothAddressAsync():



BluetoothLEDevice dev = BluetoothLEDevice::FromBluetoothAddressAsync(deviceAddr).get(); 


In the .NET assembly Windows.Device.Bluetooth, the signature of the FromBluetoothAddressAsync() function is:



inline Windows::Foundation::IAsyncOperation<Windows::Devices::Bluetooth::BluetoothLEDevice> BluetoothLEDevice::FromBluetoothAddressAsync(uint64_t bluetoothAddress)


Delphi provides interfaces to the BluetoothLEAdvertisementWatcher and BluetoothLEDevice classes, and the Received() and FromBluetoothAddressAsync() methods, inside WinAPI.Devices.Bluetooth.pas.



From the C++Builder side, we have the header files for the definitions. In Winapi.Devices.Bluetooth.Advertisement.hpp we have:



__interface DELPHIINTERFACE IBluetoothLEAdvertisementWatcher;
typedef System::DelphiInterface<IBluetoothLEAdvertisementWatcher> _di_IBluetoothLEAdvertisementWatcher;


and in WinAPI.Devices.Bluetooth.hpp we have:



  class PASCALIMPLEMENTATION TBluetoothDevice : public System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>
{
typedef System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2> inherited;

public:
...
static _di_IAsyncOperation_1__IBluetoothDevice __fastcall FromBluetoothAddressAsync(unsigned __int64 address);

public:
/* TObject.Create */ inline __fastcall TBluetoothDevice() : System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>() { }
/* TObject.Destroy */ inline __fastcall virtual ~TBluetoothDevice() { }

};


My question is : how to make instances of .NET objects in C++Builder?



I understand that a statement like:



_di_IBluetoothLEAdvertisementWatcher MyWatacher;


in C++Builder is just a declaration. This means that MyWatcher is a NULL pointer. But how to create an instance of a new (real) BluetoothLEAdvertisementWatcher object before calling its methods?



Update #1



My understanding is that for each invokable class _X in .NET assembly, delphi will generate two definitions: the interface I_X and the object T_X. We can "Create/Allocate" instances of T_X but not of I_X. In C++Builder we get another name for the interface _di_I_X.



Creating the object seems ok :



    TBluetoothLEAdvertisementWatcher *inst =
new TBluetoothLEAdvertisementWatcher();
_di_IBluetoothLEAdvertisementWatcher intf;


I tried several approaches to typecast the created T_X to _di_I_X :



//First method :



inst->GetInterface(__uuidof(IBluetoothLEAdvertisementWatcher), (void*)&intf);


//Second method :



intf = interface_cast<TBluetoothLEAdvertisementWatcher>(inst);


//Third method :



bool trans_ok = Supports(inst,__uuidof(IBluetoothLEAdvertisementWatcher),(void*)&intf);     


All of them return a NULL for intf.



I noticed that TBluetoothLEAdvertisementWatcher is declared by :



TBluetoothLEAdvertisementWatcher= class(TWinRTGenericImportFI<IBluetoothLEAdvertisementWatcherFactory, IBluetoothLEAdvertisementWatcher>)


Do you think that "the type casting issue" is related to multiple inheritance in TBluetoothLEAdvertisementWatcher ?



Update #2:



I used delphi to create an instance for me.
I created a unit2.pas with :



unit Unit2;

interface
uses
System.SysUtils, System.Bluetooth, Winapi.Devices.Bluetooth.Advertisement;

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
implementation

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
begin
Result := TBluetoothLEAdvertisementWatcher.Create;
end;
end.


Then in C++ Builder I call it by:



_di_IBluetoothLEAdvertisementWatcher intf = CreateADelphiInstance();
if (intf)
intf->ScanningMode = Winapi::Commontypes::BluetoothLEScanningMode::Active;


But I hope being able to do this directly in C++Builder.










share|improve this question

























  • Thank you for editing Remy. I was really waiting your help.

    – cairdac_rd
    Nov 27 '18 at 23:33











  • The T_X classes implement the I_X interfaces, so you can assign a T_X* pointer to an I_X* pointer. That is normal polymorphism at work. The _di_I_X types are just typedefs of the DelphiInterface helper class, which wraps I_X* pointers to handle reference counting like Delphi does natively. You should be able to use _di_IBluetoothLEAdvertisementWatcher intf = new TBluetoothLEAdvertisementWatcher(); which is the equivalent of the Delphi code you have.

    – Remy Lebeau
    Nov 29 '18 at 4:06













  • The compiler do not like to do that : [bcc64 Error] no viable conversion from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to '_di_IBluetoothLEAdvertisementWatcher' (aka 'DelphiInterface<Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher>')

    – cairdac_rd
    Nov 29 '18 at 8:50











  • the DelphiInterface class has a constructor that takes an I_X* pointer as input, so try using an explicit typecast from T_X* to I_X*: _di_IBluetoothLEAdvertisementWatcher intf = static_cast<IBluetoothLEAdvertisementWatcher*>(new TBluetoothLEAdvertisementWatcher);

    – Remy Lebeau
    Nov 29 '18 at 14:28













  • The C++ compiler is considering them two different types : [bcc64 Error] static_cast from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to 'Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher *' is not allowed.

    – cairdac_rd
    Nov 29 '18 at 19:08
















0















I tried to use the TBluetoothLE component in a multi-platform application. The code works fine on iOS. Needs some tweaking to work correctly on Android. But I am not able to make it work on Windows.



I looked during debugging at the source code on the Windows platform, and it seems to use the WinRT API. I know that writing (and testing) a generic component that works well on several platforms is not so easy. But I'm wondering if we can use the WinRT directly from the application without using the component provided by Embarcadero.



There are many working examples in C# that I tested on Windows. BluetoothLEExplorer is a very good application that show the use of WinRT to discover and communicate with BLE devices.



Delphi also provides interface files to use WinRT, but there is no sample application showing how to use it.



I would like to investigate a very simple example of calling a function inside a .NET assembly from C++Builder.



In C#, a simple example is to call FromBluetoothAddressAsync to find if a BLE device with a given address is connectable:



C# example in 3 lines of code:



1- create a Watcher to discover BLE devices



BluetoothLEAdvertisementWatcher advWatcher;
// then call its Received method
advWatcher.Received(some_callback_function_to_be_called_when_the_watcher_detect_adevice);
//the discovered BLE device address is saved in variable uint_t64 deviceAddr by the callback_function


2- get a BluetoothLEDevice object for the device using FromBluetoothAddressAsync():



BluetoothLEDevice dev = BluetoothLEDevice::FromBluetoothAddressAsync(deviceAddr).get(); 


In the .NET assembly Windows.Device.Bluetooth, the signature of the FromBluetoothAddressAsync() function is:



inline Windows::Foundation::IAsyncOperation<Windows::Devices::Bluetooth::BluetoothLEDevice> BluetoothLEDevice::FromBluetoothAddressAsync(uint64_t bluetoothAddress)


Delphi provides interfaces to the BluetoothLEAdvertisementWatcher and BluetoothLEDevice classes, and the Received() and FromBluetoothAddressAsync() methods, inside WinAPI.Devices.Bluetooth.pas.



From the C++Builder side, we have the header files for the definitions. In Winapi.Devices.Bluetooth.Advertisement.hpp we have:



__interface DELPHIINTERFACE IBluetoothLEAdvertisementWatcher;
typedef System::DelphiInterface<IBluetoothLEAdvertisementWatcher> _di_IBluetoothLEAdvertisementWatcher;


and in WinAPI.Devices.Bluetooth.hpp we have:



  class PASCALIMPLEMENTATION TBluetoothDevice : public System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>
{
typedef System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2> inherited;

public:
...
static _di_IAsyncOperation_1__IBluetoothDevice __fastcall FromBluetoothAddressAsync(unsigned __int64 address);

public:
/* TObject.Create */ inline __fastcall TBluetoothDevice() : System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>() { }
/* TObject.Destroy */ inline __fastcall virtual ~TBluetoothDevice() { }

};


My question is : how to make instances of .NET objects in C++Builder?



I understand that a statement like:



_di_IBluetoothLEAdvertisementWatcher MyWatacher;


in C++Builder is just a declaration. This means that MyWatcher is a NULL pointer. But how to create an instance of a new (real) BluetoothLEAdvertisementWatcher object before calling its methods?



Update #1



My understanding is that for each invokable class _X in .NET assembly, delphi will generate two definitions: the interface I_X and the object T_X. We can "Create/Allocate" instances of T_X but not of I_X. In C++Builder we get another name for the interface _di_I_X.



Creating the object seems ok :



    TBluetoothLEAdvertisementWatcher *inst =
new TBluetoothLEAdvertisementWatcher();
_di_IBluetoothLEAdvertisementWatcher intf;


I tried several approaches to typecast the created T_X to _di_I_X :



//First method :



inst->GetInterface(__uuidof(IBluetoothLEAdvertisementWatcher), (void*)&intf);


//Second method :



intf = interface_cast<TBluetoothLEAdvertisementWatcher>(inst);


//Third method :



bool trans_ok = Supports(inst,__uuidof(IBluetoothLEAdvertisementWatcher),(void*)&intf);     


All of them return a NULL for intf.



I noticed that TBluetoothLEAdvertisementWatcher is declared by :



TBluetoothLEAdvertisementWatcher= class(TWinRTGenericImportFI<IBluetoothLEAdvertisementWatcherFactory, IBluetoothLEAdvertisementWatcher>)


Do you think that "the type casting issue" is related to multiple inheritance in TBluetoothLEAdvertisementWatcher ?



Update #2:



I used delphi to create an instance for me.
I created a unit2.pas with :



unit Unit2;

interface
uses
System.SysUtils, System.Bluetooth, Winapi.Devices.Bluetooth.Advertisement;

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
implementation

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
begin
Result := TBluetoothLEAdvertisementWatcher.Create;
end;
end.


Then in C++ Builder I call it by:



_di_IBluetoothLEAdvertisementWatcher intf = CreateADelphiInstance();
if (intf)
intf->ScanningMode = Winapi::Commontypes::BluetoothLEScanningMode::Active;


But I hope being able to do this directly in C++Builder.










share|improve this question

























  • Thank you for editing Remy. I was really waiting your help.

    – cairdac_rd
    Nov 27 '18 at 23:33











  • The T_X classes implement the I_X interfaces, so you can assign a T_X* pointer to an I_X* pointer. That is normal polymorphism at work. The _di_I_X types are just typedefs of the DelphiInterface helper class, which wraps I_X* pointers to handle reference counting like Delphi does natively. You should be able to use _di_IBluetoothLEAdvertisementWatcher intf = new TBluetoothLEAdvertisementWatcher(); which is the equivalent of the Delphi code you have.

    – Remy Lebeau
    Nov 29 '18 at 4:06













  • The compiler do not like to do that : [bcc64 Error] no viable conversion from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to '_di_IBluetoothLEAdvertisementWatcher' (aka 'DelphiInterface<Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher>')

    – cairdac_rd
    Nov 29 '18 at 8:50











  • the DelphiInterface class has a constructor that takes an I_X* pointer as input, so try using an explicit typecast from T_X* to I_X*: _di_IBluetoothLEAdvertisementWatcher intf = static_cast<IBluetoothLEAdvertisementWatcher*>(new TBluetoothLEAdvertisementWatcher);

    – Remy Lebeau
    Nov 29 '18 at 14:28













  • The C++ compiler is considering them two different types : [bcc64 Error] static_cast from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to 'Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher *' is not allowed.

    – cairdac_rd
    Nov 29 '18 at 19:08














0












0








0








I tried to use the TBluetoothLE component in a multi-platform application. The code works fine on iOS. Needs some tweaking to work correctly on Android. But I am not able to make it work on Windows.



I looked during debugging at the source code on the Windows platform, and it seems to use the WinRT API. I know that writing (and testing) a generic component that works well on several platforms is not so easy. But I'm wondering if we can use the WinRT directly from the application without using the component provided by Embarcadero.



There are many working examples in C# that I tested on Windows. BluetoothLEExplorer is a very good application that show the use of WinRT to discover and communicate with BLE devices.



Delphi also provides interface files to use WinRT, but there is no sample application showing how to use it.



I would like to investigate a very simple example of calling a function inside a .NET assembly from C++Builder.



In C#, a simple example is to call FromBluetoothAddressAsync to find if a BLE device with a given address is connectable:



C# example in 3 lines of code:



1- create a Watcher to discover BLE devices



BluetoothLEAdvertisementWatcher advWatcher;
// then call its Received method
advWatcher.Received(some_callback_function_to_be_called_when_the_watcher_detect_adevice);
//the discovered BLE device address is saved in variable uint_t64 deviceAddr by the callback_function


2- get a BluetoothLEDevice object for the device using FromBluetoothAddressAsync():



BluetoothLEDevice dev = BluetoothLEDevice::FromBluetoothAddressAsync(deviceAddr).get(); 


In the .NET assembly Windows.Device.Bluetooth, the signature of the FromBluetoothAddressAsync() function is:



inline Windows::Foundation::IAsyncOperation<Windows::Devices::Bluetooth::BluetoothLEDevice> BluetoothLEDevice::FromBluetoothAddressAsync(uint64_t bluetoothAddress)


Delphi provides interfaces to the BluetoothLEAdvertisementWatcher and BluetoothLEDevice classes, and the Received() and FromBluetoothAddressAsync() methods, inside WinAPI.Devices.Bluetooth.pas.



From the C++Builder side, we have the header files for the definitions. In Winapi.Devices.Bluetooth.Advertisement.hpp we have:



__interface DELPHIINTERFACE IBluetoothLEAdvertisementWatcher;
typedef System::DelphiInterface<IBluetoothLEAdvertisementWatcher> _di_IBluetoothLEAdvertisementWatcher;


and in WinAPI.Devices.Bluetooth.hpp we have:



  class PASCALIMPLEMENTATION TBluetoothDevice : public System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>
{
typedef System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2> inherited;

public:
...
static _di_IAsyncOperation_1__IBluetoothDevice __fastcall FromBluetoothAddressAsync(unsigned __int64 address);

public:
/* TObject.Create */ inline __fastcall TBluetoothDevice() : System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>() { }
/* TObject.Destroy */ inline __fastcall virtual ~TBluetoothDevice() { }

};


My question is : how to make instances of .NET objects in C++Builder?



I understand that a statement like:



_di_IBluetoothLEAdvertisementWatcher MyWatacher;


in C++Builder is just a declaration. This means that MyWatcher is a NULL pointer. But how to create an instance of a new (real) BluetoothLEAdvertisementWatcher object before calling its methods?



Update #1



My understanding is that for each invokable class _X in .NET assembly, delphi will generate two definitions: the interface I_X and the object T_X. We can "Create/Allocate" instances of T_X but not of I_X. In C++Builder we get another name for the interface _di_I_X.



Creating the object seems ok :



    TBluetoothLEAdvertisementWatcher *inst =
new TBluetoothLEAdvertisementWatcher();
_di_IBluetoothLEAdvertisementWatcher intf;


I tried several approaches to typecast the created T_X to _di_I_X :



//First method :



inst->GetInterface(__uuidof(IBluetoothLEAdvertisementWatcher), (void*)&intf);


//Second method :



intf = interface_cast<TBluetoothLEAdvertisementWatcher>(inst);


//Third method :



bool trans_ok = Supports(inst,__uuidof(IBluetoothLEAdvertisementWatcher),(void*)&intf);     


All of them return a NULL for intf.



I noticed that TBluetoothLEAdvertisementWatcher is declared by :



TBluetoothLEAdvertisementWatcher= class(TWinRTGenericImportFI<IBluetoothLEAdvertisementWatcherFactory, IBluetoothLEAdvertisementWatcher>)


Do you think that "the type casting issue" is related to multiple inheritance in TBluetoothLEAdvertisementWatcher ?



Update #2:



I used delphi to create an instance for me.
I created a unit2.pas with :



unit Unit2;

interface
uses
System.SysUtils, System.Bluetooth, Winapi.Devices.Bluetooth.Advertisement;

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
implementation

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
begin
Result := TBluetoothLEAdvertisementWatcher.Create;
end;
end.


Then in C++ Builder I call it by:



_di_IBluetoothLEAdvertisementWatcher intf = CreateADelphiInstance();
if (intf)
intf->ScanningMode = Winapi::Commontypes::BluetoothLEScanningMode::Active;


But I hope being able to do this directly in C++Builder.










share|improve this question
















I tried to use the TBluetoothLE component in a multi-platform application. The code works fine on iOS. Needs some tweaking to work correctly on Android. But I am not able to make it work on Windows.



I looked during debugging at the source code on the Windows platform, and it seems to use the WinRT API. I know that writing (and testing) a generic component that works well on several platforms is not so easy. But I'm wondering if we can use the WinRT directly from the application without using the component provided by Embarcadero.



There are many working examples in C# that I tested on Windows. BluetoothLEExplorer is a very good application that show the use of WinRT to discover and communicate with BLE devices.



Delphi also provides interface files to use WinRT, but there is no sample application showing how to use it.



I would like to investigate a very simple example of calling a function inside a .NET assembly from C++Builder.



In C#, a simple example is to call FromBluetoothAddressAsync to find if a BLE device with a given address is connectable:



C# example in 3 lines of code:



1- create a Watcher to discover BLE devices



BluetoothLEAdvertisementWatcher advWatcher;
// then call its Received method
advWatcher.Received(some_callback_function_to_be_called_when_the_watcher_detect_adevice);
//the discovered BLE device address is saved in variable uint_t64 deviceAddr by the callback_function


2- get a BluetoothLEDevice object for the device using FromBluetoothAddressAsync():



BluetoothLEDevice dev = BluetoothLEDevice::FromBluetoothAddressAsync(deviceAddr).get(); 


In the .NET assembly Windows.Device.Bluetooth, the signature of the FromBluetoothAddressAsync() function is:



inline Windows::Foundation::IAsyncOperation<Windows::Devices::Bluetooth::BluetoothLEDevice> BluetoothLEDevice::FromBluetoothAddressAsync(uint64_t bluetoothAddress)


Delphi provides interfaces to the BluetoothLEAdvertisementWatcher and BluetoothLEDevice classes, and the Received() and FromBluetoothAddressAsync() methods, inside WinAPI.Devices.Bluetooth.pas.



From the C++Builder side, we have the header files for the definitions. In Winapi.Devices.Bluetooth.Advertisement.hpp we have:



__interface DELPHIINTERFACE IBluetoothLEAdvertisementWatcher;
typedef System::DelphiInterface<IBluetoothLEAdvertisementWatcher> _di_IBluetoothLEAdvertisementWatcher;


and in WinAPI.Devices.Bluetooth.hpp we have:



  class PASCALIMPLEMENTATION TBluetoothDevice : public System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>
{
typedef System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2> inherited;

public:
...
static _di_IAsyncOperation_1__IBluetoothDevice __fastcall FromBluetoothAddressAsync(unsigned __int64 address);

public:
/* TObject.Create */ inline __fastcall TBluetoothDevice() : System::Win::Winrt::TWinRTGenericImportS2__2<_di_IBluetoothDeviceStatics,_di_IBluetoothDeviceStatics2>() { }
/* TObject.Destroy */ inline __fastcall virtual ~TBluetoothDevice() { }

};


My question is : how to make instances of .NET objects in C++Builder?



I understand that a statement like:



_di_IBluetoothLEAdvertisementWatcher MyWatacher;


in C++Builder is just a declaration. This means that MyWatcher is a NULL pointer. But how to create an instance of a new (real) BluetoothLEAdvertisementWatcher object before calling its methods?



Update #1



My understanding is that for each invokable class _X in .NET assembly, delphi will generate two definitions: the interface I_X and the object T_X. We can "Create/Allocate" instances of T_X but not of I_X. In C++Builder we get another name for the interface _di_I_X.



Creating the object seems ok :



    TBluetoothLEAdvertisementWatcher *inst =
new TBluetoothLEAdvertisementWatcher();
_di_IBluetoothLEAdvertisementWatcher intf;


I tried several approaches to typecast the created T_X to _di_I_X :



//First method :



inst->GetInterface(__uuidof(IBluetoothLEAdvertisementWatcher), (void*)&intf);


//Second method :



intf = interface_cast<TBluetoothLEAdvertisementWatcher>(inst);


//Third method :



bool trans_ok = Supports(inst,__uuidof(IBluetoothLEAdvertisementWatcher),(void*)&intf);     


All of them return a NULL for intf.



I noticed that TBluetoothLEAdvertisementWatcher is declared by :



TBluetoothLEAdvertisementWatcher= class(TWinRTGenericImportFI<IBluetoothLEAdvertisementWatcherFactory, IBluetoothLEAdvertisementWatcher>)


Do you think that "the type casting issue" is related to multiple inheritance in TBluetoothLEAdvertisementWatcher ?



Update #2:



I used delphi to create an instance for me.
I created a unit2.pas with :



unit Unit2;

interface
uses
System.SysUtils, System.Bluetooth, Winapi.Devices.Bluetooth.Advertisement;

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
implementation

function CreateADelphiInstance() : IBluetoothLEAdvertisementWatcher;
begin
Result := TBluetoothLEAdvertisementWatcher.Create;
end;
end.


Then in C++ Builder I call it by:



_di_IBluetoothLEAdvertisementWatcher intf = CreateADelphiInstance();
if (intf)
intf->ScanningMode = Winapi::Commontypes::BluetoothLEScanningMode::Active;


But I hope being able to do this directly in C++Builder.







.net delphi interface c++builder






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 2:00







cairdac_rd

















asked Nov 27 '18 at 22:00









cairdac_rdcairdac_rd

12




12













  • Thank you for editing Remy. I was really waiting your help.

    – cairdac_rd
    Nov 27 '18 at 23:33











  • The T_X classes implement the I_X interfaces, so you can assign a T_X* pointer to an I_X* pointer. That is normal polymorphism at work. The _di_I_X types are just typedefs of the DelphiInterface helper class, which wraps I_X* pointers to handle reference counting like Delphi does natively. You should be able to use _di_IBluetoothLEAdvertisementWatcher intf = new TBluetoothLEAdvertisementWatcher(); which is the equivalent of the Delphi code you have.

    – Remy Lebeau
    Nov 29 '18 at 4:06













  • The compiler do not like to do that : [bcc64 Error] no viable conversion from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to '_di_IBluetoothLEAdvertisementWatcher' (aka 'DelphiInterface<Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher>')

    – cairdac_rd
    Nov 29 '18 at 8:50











  • the DelphiInterface class has a constructor that takes an I_X* pointer as input, so try using an explicit typecast from T_X* to I_X*: _di_IBluetoothLEAdvertisementWatcher intf = static_cast<IBluetoothLEAdvertisementWatcher*>(new TBluetoothLEAdvertisementWatcher);

    – Remy Lebeau
    Nov 29 '18 at 14:28













  • The C++ compiler is considering them two different types : [bcc64 Error] static_cast from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to 'Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher *' is not allowed.

    – cairdac_rd
    Nov 29 '18 at 19:08



















  • Thank you for editing Remy. I was really waiting your help.

    – cairdac_rd
    Nov 27 '18 at 23:33











  • The T_X classes implement the I_X interfaces, so you can assign a T_X* pointer to an I_X* pointer. That is normal polymorphism at work. The _di_I_X types are just typedefs of the DelphiInterface helper class, which wraps I_X* pointers to handle reference counting like Delphi does natively. You should be able to use _di_IBluetoothLEAdvertisementWatcher intf = new TBluetoothLEAdvertisementWatcher(); which is the equivalent of the Delphi code you have.

    – Remy Lebeau
    Nov 29 '18 at 4:06













  • The compiler do not like to do that : [bcc64 Error] no viable conversion from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to '_di_IBluetoothLEAdvertisementWatcher' (aka 'DelphiInterface<Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher>')

    – cairdac_rd
    Nov 29 '18 at 8:50











  • the DelphiInterface class has a constructor that takes an I_X* pointer as input, so try using an explicit typecast from T_X* to I_X*: _di_IBluetoothLEAdvertisementWatcher intf = static_cast<IBluetoothLEAdvertisementWatcher*>(new TBluetoothLEAdvertisementWatcher);

    – Remy Lebeau
    Nov 29 '18 at 14:28













  • The C++ compiler is considering them two different types : [bcc64 Error] static_cast from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to 'Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher *' is not allowed.

    – cairdac_rd
    Nov 29 '18 at 19:08

















Thank you for editing Remy. I was really waiting your help.

– cairdac_rd
Nov 27 '18 at 23:33





Thank you for editing Remy. I was really waiting your help.

– cairdac_rd
Nov 27 '18 at 23:33













The T_X classes implement the I_X interfaces, so you can assign a T_X* pointer to an I_X* pointer. That is normal polymorphism at work. The _di_I_X types are just typedefs of the DelphiInterface helper class, which wraps I_X* pointers to handle reference counting like Delphi does natively. You should be able to use _di_IBluetoothLEAdvertisementWatcher intf = new TBluetoothLEAdvertisementWatcher(); which is the equivalent of the Delphi code you have.

– Remy Lebeau
Nov 29 '18 at 4:06







The T_X classes implement the I_X interfaces, so you can assign a T_X* pointer to an I_X* pointer. That is normal polymorphism at work. The _di_I_X types are just typedefs of the DelphiInterface helper class, which wraps I_X* pointers to handle reference counting like Delphi does natively. You should be able to use _di_IBluetoothLEAdvertisementWatcher intf = new TBluetoothLEAdvertisementWatcher(); which is the equivalent of the Delphi code you have.

– Remy Lebeau
Nov 29 '18 at 4:06















The compiler do not like to do that : [bcc64 Error] no viable conversion from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to '_di_IBluetoothLEAdvertisementWatcher' (aka 'DelphiInterface<Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher>')

– cairdac_rd
Nov 29 '18 at 8:50





The compiler do not like to do that : [bcc64 Error] no viable conversion from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to '_di_IBluetoothLEAdvertisementWatcher' (aka 'DelphiInterface<Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher>')

– cairdac_rd
Nov 29 '18 at 8:50













the DelphiInterface class has a constructor that takes an I_X* pointer as input, so try using an explicit typecast from T_X* to I_X*: _di_IBluetoothLEAdvertisementWatcher intf = static_cast<IBluetoothLEAdvertisementWatcher*>(new TBluetoothLEAdvertisementWatcher);

– Remy Lebeau
Nov 29 '18 at 14:28







the DelphiInterface class has a constructor that takes an I_X* pointer as input, so try using an explicit typecast from T_X* to I_X*: _di_IBluetoothLEAdvertisementWatcher intf = static_cast<IBluetoothLEAdvertisementWatcher*>(new TBluetoothLEAdvertisementWatcher);

– Remy Lebeau
Nov 29 '18 at 14:28















The C++ compiler is considering them two different types : [bcc64 Error] static_cast from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to 'Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher *' is not allowed.

– cairdac_rd
Nov 29 '18 at 19:08





The C++ compiler is considering them two different types : [bcc64 Error] static_cast from 'Winapi::Devices::Bluetooth::Advertisement::TBluetoothLEAdvertisementWatcher *' to 'Winapi::Devices::Bluetooth::Advertisement::IBluetoothLEAdvertisementWatcher *' is not allowed.

– cairdac_rd
Nov 29 '18 at 19:08












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53508873%2fcalling-net-assembly-from-delphi-cbuilder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53508873%2fcalling-net-assembly-from-delphi-cbuilder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Unable to find Lightning Node

Futebolista