ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing a variant object to a C++ dll (https://www.excelbanter.com/excel-programming/374327-passing-variant-object-c-dll.html)

Martin[_29_]

Passing a variant object to a C++ dll
 
Hello all,

I'm trying to send to a C++ DLL a Range object from a VB macro (that is
called from Excel).

I first achieved to copy the content of the range object into a VB
array of Double. I could get it as a double* from c++ and this work
perfectly. I however fear that all cells are not contiguous in some
cases (and I could thus get a seg.fault), and I'm also trying to use a
clean & generic way of passing VB data to C++.

I started writing this c++ function :

DLLEXPORT void CALLCONVENTION get_variant( VARIANT* variant )
{
switch(variant-vt){
case VT_DISPATCH:
IDispatch *something = variant-pdispVal;
break;
//... other cases follow

}

My question is: how may I have information on the object type that is
pointed by "something". May I get the list of member functions of
"something".

I expect to get a VT_ARRAY (i.e. SAFEARRAY?) and then use the
SafeArrayGetElement function...

Thanks in advance for your help!

Martin


[email protected][_2_]

Passing a variant object to a C++ dll
 

The best way to pass a Range to a C++ DLL is through the Excel C API.
This api has been upgraded along with Excel since the 95 verstion. The
main object is a union, called an XLOPER.

You can use RapidXLL to build this interface automatically (the process
then becomes a one-liner). RapidXLL will automatically interface your
native C / C++ to both Excel and the .NET framework. Please visit
http://www.RapidXLL.net for free samples.

Sincerely,

The RapidXLL Team


Martin wrote:
Hello all,

I'm trying to send to a C++ DLL a Range object from a VB macro (that is
called from Excel).

I first achieved to copy the content of the range object into a VB
array of Double. I could get it as a double* from c++ and this work
perfectly. I however fear that all cells are not contiguous in some
cases (and I could thus get a seg.fault), and I'm also trying to use a
clean & generic way of passing VB data to C++.

I started writing this c++ function :

DLLEXPORT void CALLCONVENTION get_variant( VARIANT* variant )
{
switch(variant-vt){
case VT_DISPATCH:
IDispatch *something = variant-pdispVal;
break;
//... other cases follow

}

My question is: how may I have information on the object type that is
pointed by "something". May I get the list of member functions of
"something".

I expect to get a VT_ARRAY (i.e. SAFEARRAY?) and then use the
SafeArrayGetElement function...

Thanks in advance for your help!

Martin




All times are GMT +1. The time now is 03:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com