• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

Pass Array handel in UDT to DLL

I have a function in a c++ dll that gets a pointer to double array. inside a struct.
I defined a UDT in VB5 and passed all the rest of the UDT fields fine, the problem is with this array.
type Type1
  par1 as Integer
  myArr as double
end type
dim myType as Type1 , arr() as double
ReDim arr(1000)

I don't know how to set myType.myArr to point to arr


if I pass the array seperetly it's easy and it works but I need it in the UDT.
CALL dllfunction(myType,arr(0))

Is this posible???
HELP
Shai
0
shaii
Asked:
shaii
1 Solution
 
corvanderlindenCommented:
Try this:

type Type1
  par1 as Integer
  myArr() as double
end type
dim myType as Type1

ReDim myArr(1000)

0
 
shaiiAuthor Commented:
I have tried this before and now again.
but it doesn't seem to work.

I'll make it clear.
In the dll the struct is waiting for a pointer to a double array

if it wasn't inside a struct I would
have passed arr(0) to the function
but it is!!!
HELP
0
 
corvanderlindenCommented:
I do not know the C code but one thing is important

In VB an integer is 2 bytes
In C it is 4

Try
type Type1
  par1 as long
  myArr() as double
end type
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mcriderCommented:
Have you read these microsoft KB articles:

HOWTO: Fill a 32-bit VBA Array of UDType via a Visual C++ DLL
http://support.microsoft.com/support/kb/articles/Q171/5/83.ASP 
 
HOWTO: Pass Array of UDTs with Variable Length Strings to C/C++
http://support.microsoft.com/support/kb/articles/Q194/6/09.ASP 
 


Cheers!

0
 
shaiiAuthor Commented:
corvander...
  the problem is with passing the double array not with the int
(I know I should pass it as long it was only for an example, my UDT is much bigger)

mcrider:
I have checked these sites but they are concerning passing arrays of UDT's.
while I have and UDT and a pointer to an array inside it I need to pass!

HELP!!!
0
 
thomasschaeferCommented:
Hi,

well you only need the pointer to arr().
I am not very familiar with c but in ASM i would do it like this.
Write a c-function in your dll that returns the array-pointer. and make the type like this.

type Type1
  par1 as Integer
  myArr as LONG    ---> not double
end type

dim myType as Type1 , arr() as double
ReDim arr(1000)

mytype.myarr=dllretpointer(arr(0))

now it should be easy to access the array from your dll.

Thomas

0
 
shaiiAuthor Commented:
I have solved the problem.
Using VarPtr(arr(0))
it returns a pointer to the array.

10x any way.
Shai
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now