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

Posted on 2000-01-13
Medium Priority
Last Modified: 2008-03-17
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.
Question by:laax
  • 2
LVL 14

Accepted Solution

mcrider earned 400 total points
ID: 2350304
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



Author Comment

ID: 2352152
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 ...

LVL 14

Expert Comment

ID: 2371342
Have you tried something like:

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


Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question