passing double arrays from vb to a c dll using a type lib

S

Sascha Herpers

Hi,

[I posted this on comp.lang.basic.visual.misc, but nobody answered to
it, so I figured this would be a more c-related question. Maybe you can
help...]

I wrote a c dll with a type library to use it in vb. No problem,
everything works fine.

Now I needed to pass an array of type double to the dll. I defined the
function in the type library like this:
double VBEXPORT aigIGApproximation([in] double intervalCount,
[in] SAFEARRAY(double) lambda_i,
[in] SAFEARRAY(double) alpha_i[], [in] double iMax,
[out] double* gammaValue);
with
#define VBEXPORT __declspec( dllexport ) __stdcall

In the object browser (in VB IDE) this function is shown as this:
Function aigIGApproximation(intervalCount As Double,
lambda_i() As Double, alpha_i() As Double,
iMax As Double, gammaValue As Double) As Double

That /looks/ good, but doesn't work. VB says I would use a incompatible
parameter type.

What am I doing wrong? How do I have to declare the type lib to make the
dll accept my double array within VB?

Any hints?

Sascha
 
R

Richard Bos

Sascha Herpers said:
[I posted this on comp.lang.basic.visual.misc, but nobody answered to
it, so I figured this would be a more c-related question.

It isn't. It _may_ be a M$-Visual-C++-4.984.288a-for-M$-Windows-XP
question, but it isn't C.
I wrote a c dll with a type library to use it in vb. No problem,
everything works fine.

Now I needed to pass an array of type double to the dll. I defined the
function in the type library like this:

(That's a declaration, btw, not a definition.)
double VBEXPORT aigIGApproximation

This isn't C, unless you've #defined VBEXPORT or aigIGApproximation to
be something legal (e.g., the word static, or just whitespace).
([in] double intervalCount,
^^^^

This is a syntax error in C. Ditto for all the other parameters, and for
[out].
[in] SAFEARRAY(double) lambda_i,
^^^^^^^^^^^^^^^^^
This isn't C, either, unless you've #defined SAFEARRAY to something
sensible.
[in] SAFEARRAY(double) alpha_i[], [in] double iMax,
[out] double* gammaValue);
with
#define VBEXPORT __declspec( dllexport ) __stdcall

Ah, I see (I hope you didn't put the #define after the function
declaration in your code as well - that wouldn't work). Well, _that_
isn't C, either. Again, it may be VC++-WinXP, but it isn't ISO C, and we
can't guarantee that it isn't the source of your problems.
In the object browser (in VB IDE) this function is shown as this:
Function aigIGApproximation(intervalCount As Double,
lambda_i() As Double, alpha_i() As Double,
iMax As Double, gammaValue As Double) As Double

That /looks/ good, but doesn't work. VB says I would use a incompatible
parameter type.

Since I can't even work out what the type for the C function is supposed
to be, and the type for the VB function is off-topic here, I couldn't
possibly comment. But a VC-specific group just might.

Richard
 
R

Robert Stankowic

Sascha Herpers said:
Hi,

[I posted this on comp.lang.basic.visual.misc, but nobody answered to
it, so I figured this would be a more c-related question. Maybe you can
help...]

Sorry, it isn't
[OT]pass the first elem of the array ByRef maybe[/OT]

snip

Robert
 
M

Mark McIntyre

Hi,

[I posted this on comp.lang.basic.visual.misc, but nobody answered to
it, so I figured this would be a more c-related question.

Its not.

You probably need to read the MSDN online tutorials on passing arrays
between VC and VB. They're actually quite good. As I recall, the bit
you're missing is byref or byval in the VB declaration, one or the
other. But do read the tutorials.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top