473,395 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Variant, SafeArray.....etc

I'm using VC6.
i have a DLL written in VC6 and used by VB6( and VBA Excel),
i use SafeArray as parameter, the array is created(declared), in VB
and C++ fill it.

now i need VC++ to get an array of array of different sizes, and VB
can't know the size of these arrays, so the arrays will be 'created'
in VC.

here the code that i use(and it crashes):

void __declspec(dllexport) CALLBACK Remplir_table(LPSAFEARRAY FAR
*tab1)
{
VARIANT HUGEP * CONTENU;
SAFEARRAYBOUND sabound[1]; // 1-D array
SAFEARRAY FAR* psa = NULL; // SAFEARRAY structure pointer
VARIANT TEMPORARY;

VariantInit(&TEMPORARY);

SafeArrayAccessData(*tab1, (void HUGEP**)&CONTENU);

sabound[0].lLbound = 0;
sabound[0].cElements = 2;

for (int i = 0; i<2; i++)
{
psa = SafeArrayCreate( VT_R4, 1, sabound );
float HUGEP* ResData;
SafeArrayAccessData(psa, (void HUGEP**)&ResData);
ResData[0] = 1.5; //just for test
ResData[1] = 0.75;//just for test
V_VT(&TEMPORARY ) = VT_ARRAY | VT_R4;
V_ARRAY(&TEMPORARY) = psa;
SafeArrayUnaccessData(psa);
VariantCopy(&CONTENU[i],&TEMPORARY);

}
SafeArrayUnaccessData(*tab1);
}

the vb side:
Dim tab1(1) As Variant
Call Remplir_table(tab1)

Jul 31 '07 #1
2 4101

i did a mistake, the problem have nothing to do with Variant or
SafeArray, i just used an old code for testing how to create a table
of tables of different sizes, and i didn't see that in excel i had a
function, not a sub, so excel was waiting for a return value that C++
doesn't send, and the fact that it crashes at VariantCopy, confused
me, so i didn't think about other possible problems.

PS:i'm sorry for the confusion

Jul 31 '07 #2
On Jul 31, 2:06 pm, Simply_Red <Simply.Re...@gmail.comwrote:
[OT redacted]
PS:i'm sorry for the confusion
1. Congratulations on finding your mistake.
2. In the future, when you post, please consider this: Your question
was VC specific
(even more, it was VC6 specific). This is off-topic for this
newsgroup. You might
want to consider reading the FAQ (http://www.parashift.com/c++-faq-
lite) and in particular
section 5 (http://www.parashift.com/c++-faq-lite/how-to-post.html)
to see what is topical.

In general, ask yourself, "Would my question be essentially the same
in a different programming language?".
If you answer yes, then you probably should post in a newsgroup
dedicated to general programming.

Also ask yourself, "Does this question make sense for a different
platform (i.e. Linux/Mac instead of Windows)?".
If you answer yes, then it would probably be on topic here. If the
answer is no, then you are probably better off
posting to a newsgroup dedicated to your platform.

In both cases, a reasonable set of suggested newsgroups can be found
in FAQ 5.9.

Please feel free to bring your C++ specific questions here, we'll be
glad to help.
Aug 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mic | last post by:
I'm stuck with following problem. Using webbrowser control I try to make custom-made request. I found working example of this written in VBS but porting it to Python doesn't seem to work. The key...
2
by: Ken Layton | last post by:
Attempting to pass a VBScript Array of Bytes to a C# Managed COM object has resulted in some very undesirable and strange behavior. When definining a method in my C# COM class as "void Write(byte...
2
by: Duncan Winn | last post by:
I am passing back a Variant* from COM to .NET. The pointer actually holds a void**. i.e. void ** row_array; row_array = (void**)new byte; row_array = (void*)70186; row_array =...
0
by: maddala | last post by:
Hi, I need help to wrap a C++ DLL using C# PInvoke. I have the following function which needs a arapper function. VARIANT _stdcall retVariantArray(void) { COleSafeArray saRet; DWORD...
0
by: Michael Moreno | last post by:
Hello, I do not find the solution on how to convert this code into .Net public function MyFunc() as variant Dim R as Variant Redim R(0 to 10) as double MyFunc = R end function
0
by: .::alex::. | last post by:
Hello, Maybe you already guess the problem. I have a COM with a method in a Interface like that: HRESULT GetArray(VARIANT *pVal); so this method will return a VARIANT. This VARIANT contains...
1
by: Brendan Grant | last post by:
I’ve got a C# library that I’ve built into a COM component that will be used from a VC++ 6 application and while the creation of the COM object side of things seem to be working fine, using the...
4
by: Claus77 | last post by:
Hi there, I've got a little problem with the following: I'm just writing a com-application in C++ with VS-6, which should also be used with VB-Script, so I have to use variables of type...
5
by: Maxim | last post by:
Hi all, I'm calling a COM Interface method that returnes SafeArray wrapped into variant. Is it possible to convert it to managed array? Because working with SAFEARRAY directly is a bit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.