How to pass an array of structure from VB to C DLL

I Have a VB User defined Type
Type Owner
  Ownerid as string * 10
  Ownername as string * 20
End Type
Dim Ownerstruct(10) as Owner

Now how will i pass a reference of this type to a C DLL
The C DLL will later write into this structure after which the VB APP will use it.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Check out these microsoft KB articles:

How to Pass User-Defined Structure Containing Strings to DLL 

HOWTO: Pass a Point Structure to the Windows API by Value 



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
laaxAuthor Commented:
Hi mcrider,
   Thanks for your response yaar.
Let me explain my requirement more clearly.  

  I have a C DLL.  That should be used
both by another C program(later will be converted to .dll) and VB program.  With the same interface(function) both
C & VB should communicate with the C-DLL.


typedef struct
   char cOwnerID[11];
   char cOwnerNm[40];

owner **ppOwnerList;

main ()
  ppOwnerList = (owner**) malloc ( sizeof(owner*) * nRecCount );
  for ( int i = 0; i < nRecCount; i++ )
    ppOwnerList[i] = ( owner* ) malloc( sizeof(owenr) );

  // Then I pass this to C -Dll function
  myFunc(ppOwnerList, nRecCount);

} // end of main()

myFunc() has to populate the array of structures I pass and it works fine.

I want to call the same myFunc() from VB.

 How do I pass an array of structure from VB and populate
its fields inside myFunc() and get the value in VB?

For Ex.

Type Owner
  Ownerid as string * 10
  Ownername as string * 20
End Type
Dim OwnerStruct(10) as Owner

   I want to pass OwnerStruct() array to
the same myFunc() and get it populated.

  Your previous answer tell how to pass argument by 'by value', but I want 'by Ref'.  
  Waiting for solution ...

Have you tried something like:

   Declare Sub myFunc Lib "myDll" (ByRef N As Owner)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.