![]() |
#1
|
|||
|
|||
![]()
I wonder how can I pass a CorelDRAW object, namely ShapeRange object, to a DLL function as an argument. I would prefer to pass the object by reference rather than by value.
In VBA I declare function: Code:
Declare Function myFunc Lib "test.dll" Alias "_myFunc@4" (ByRef aSr As ShapeRange) As Double Code:
Dim aSr As New ShapeRange Dim x As Double Set aSr=ActiveSelection.Shapes.All x=myFunc(aSr) MsgBox=("Pi is " & x) Code:
extern "C" double _stdcall myFunc(VARIANT& aShapeRange) { double x; x=3.14; return x; } So far so good - no errors are generated and Message Box shows "Pi is 3.14". Thus the aShapeRange object must have been accepted by the DLL. But how can I access any member of the aShapeRange object within the function? Last edited by Tomasz; 04-04-2009 at 16:15. |
#2
|
||||
|
||||
![]()
First of all, you can't use references in VBA, so can't do VARIANT&
If you declare VARIANT, then you should do so in your VBA declaration as well: Code:
Declare Function myFunc Lib "test.dll" Alias "_myFunc@4" (ByVal aSr As Variant) As Double Code:
extern "C" double _stdcall myFunc(VARIANT aShapeRange) { double x; x=3.14; return x; } Code:
Declare Function myFunc Lib "test.dll" Alias "_myFunc@4" (ByVal aSr As Object) As Double Code:
extern "C" double _stdcall myFunc(IDispatch* aShapeRange) { double x; x=3.14; return x; } This way once you've got IDispatch, you can use IDispatch::QueryInterface to get the IDrawShapeRange (or IVGShapreRange) interface: Code:
extern "C" double _stdcall myFunc(IDispatch* aShapeRange) { double dResult = 0.0; IDrawShapeRange* pIShapeRange = NULL; HRESULT hr = aShapeRange->QueryInteface(__uuidof(IDrawShapeRange), &pIShapeRange); if(SUCCEEDED(hr)) { long nCount = 0; hr = pIShapeRange->get_Count(&nCount); if(SUCCEEDED(hr)) { dResult = static_cast<double>(nCount); } pIShapeRange->Release(); } return dResult; } |
#3
|
|||
|
|||
![]()
Alex,
thank you very much for directing me at IDispatch. It should resolve my problem. Hovewer my VC++ builder refuses to build the code you have suggested. The problem is within: Code:
HRESULT hr = aShapeRange->QueryInterface(__uuidof(IDrawShapeRange), &pIShapeRange); error C2664: 'HRESULT IUnknown::QueryInterface(const IID &,void **)' : cannot convert parameter 2 from 'CorelDRAW::IDrawShapeRange **' to 'void **' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast. How it is possible at all?? __uuidof(IDrawShapeRange) refers to IDrawShapeRange Struct GUID in coreldraw.tlh. At lease code definition window in VC++ enviroment properly identifies IDrawShapeRange struct when __uuidof(IDrawShapeRange) is highlighted. &pIShapeRange is a variable refered to by the pointer of the same IDrawShapeRange type as above! So how these types can be unrelated?? PS. Due to constant problem with my CDR X4 vs. VC++ 2008 installation I have tested this on the machine with CGS 12 and VC++ 2008 EE. Last edited by Tomasz; 08-04-2009 at 16:01. |
#5
|
|||
|
|||
![]()
Alex,
thank you very much! You are great! Now it works flawlessly. I only wonder why (void**) declaration? After all pIShapeRange pointer has been already declared as IDrawShapeRange*. I must learn more about IDispatch method... It is essential when one wants to make expansions for third party software. Tomasz |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem pass argument to COM | MarcinK | CorelDRAW/Corel DESIGNER VBA | 0 | 04-12-2008 10:05 |
start PAINT12 with argument ("/NOSPLASH" no effect!) | lebaron | Corel Photo-Paint VBA | 1 | 13-08-2008 03:57 |
function delete after duplicate | dominiqueL | CorelDRAW/Corel DESIGNER VBA | 2 | 18-10-2003 00:35 |
Function names | Lev | Oberon Function Plotter | 1 | 29-08-2003 11:04 |
How can I get data from function? | Elie | CorelDRAW/Corel DESIGNER VBA | 3 | 15-05-2003 05:08 |