03-15-2013, 11:35 AM
Hi,
Please, I don't know how to pass a string variable from C++ to QM. Any help?
Regards
Please, I don't know how to pass a string variable from C++ to QM. Any help?
Regards
Passing C++ strings by reference
|
03-15-2013, 11:35 AM
Hi,
Please, I don't know how to pass a string variable from C++ to QM. Any help? Regards
03-15-2013, 11:42 AM
When QM macro calls dll function?
03-15-2013, 11:45 AM
Yes, when QM calls a dll function. I've tried char* and char*& with no results.
With other type of data, no problem.
03-15-2013, 12:00 PM
What strings the dll uses - ANSI or Unicode? If char*, it is ANSI. It's better to use Unicode strings, because ANSI string encoding does not match QM string encoding in Unicode mode (UTF-8), and then dll should know QM encoding and give correct string.
03-15-2013, 12:22 PM
Oh thanks!.
Do you mind to post a little example of how to pass a variable string from a dll function? Thanks in advance.
03-15-2013, 12:28 PM
Can do like most Windows API functions, eg GetWindowText.
If using Unicode strings, easier is to allocate and return BSTR, eg with SysAllocString. With ANSI strings not so easy.
03-15-2013, 12:33 PM
i'll take a look at it later. Thanks.
03-15-2013, 12:51 PM
03-23-2013, 07:59 AM
It worked very well. Thanks for your reply.
Is it possible to pass arrays of strings and arrays of int/double data?
03-23-2013, 08:06 AM
How the array is initially stored in the C++ function?
03-23-2013, 08:13 AM
03-23-2013, 09:53 AM
Done for int/double:
Macro Macro205 dll "myDLL" double'myfunc C++ extern "C" __declspec(dllexport) double myfunc(double *pointerElement0, int arrlen); Any ideas on how to receive an array of int or str?
03-23-2013, 06:50 PM
Macro Macro2009
dll "..." !myfunc ARRAY(BSTR)a extern "C" __declspec(dllexport) bool myfunc(SAFEARRAY* a) //ARRAY(BSTR) { if(!a || !(a->fFeatures&FADF_BSTR) || a->cDims!=1 || a->rgsabound[0].lLbound || a->cLocks) return 0; BSTR* p=(BSTR*)a->pvData, *pe=p+a->rgsabound[0].cElements; for(; p<pe; p++) *p=SysAllocString(L"test"); return true; } It is possible to make calling the function simpler. For example, set a callback function that allocates array and converts BSTR to str. Then caller will not have to do it.
08-07-2013, 01:20 AM
Hi again.
Thanks for your help on this topic. I love QM for fast development and I use some dll in C in the main QM program when performance is crucial. If you don't mind, I would need some further help in this area. I know that is out of the scope of this forum but maybe it will also useful for some QM fellows. My question is for resizing the safearray after populated. I have checked the MS docs about safearray resize, but there are no examples and with so many pointers I am a little lost. I have used tricks like tokens and checked in QM, but it is not very elegant. In QM we use 'redim' but how to resize the safearray from C++ before to return to QM? Any examples, please? Thanks in advance for your help.
08-07-2013, 05:38 AM
C++
#include <oleauto.h> QM Macro Macro2114 dll "test.dll" #ResizeSafeArray ARRAY*a n vt
08-07-2013, 07:09 AM
Thank you! I spent hours trying to deal with this!
This piece of code is really useful and expands the QM capabilities to new frontiers. Thanks again and have a nice day!
04-06-2016, 08:01 AM
Good morning!
Any help on how to use SAFEARRAY with 2 dimensions in C++, please? Thanks Gintaras Wrote:Macro Macro2009
04-06-2016, 01:16 PM
a->cDims will be 2.
And there will be a->rgsabound[0] and a->rgsabound[1]. They define each dimension. Maybe swapped, ie 0 is the second dimension, 1 is the first, don't remember. Then pe=p+a->rgsabound[0].cElements*rgsabound[1].cElements. All elements are in the single memory block p that is only logically divided into dimensions.
04-07-2016, 11:58 AM
Wow! hock:
It works fine! Thanks for your help. Best regards. |
« Next Oldest | Next Newest »
|