Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2005, 12:40 AM
Authorized User
 
Join Date: Jun 2005
Location: , , India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to pass structure to DLL & retrieve them?

Hi

how could i pass a structure to a DLL and retrieve the values of the user-defined type structure from a DLL??? in VB



Reply With Quote
  #2 (permalink)  
Old July 14th, 2005, 01:14 AM
Friend of Wrox
Points: 687, Level: 9
Points: 687, Level: 9 Points: 687, Level: 9 Points: 687, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamilnadu, India.
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

Create a structure in the dll as public

DLL Code #####################################

Public Type struct_CustInfo
strCustName as String
intCustAge as Integer
End Type

Public Function GetCustInfo( _
Byval sCI as struct_CustInfo) as struct_CustInfo
Dim sInfo as struct_CustInfo
write you code ...
and say
GetCustInfo = sInfo
End Function

NOW in the front-end CODE ##################

Declare that same structure here from that DLL

Dim si1 as struct_CustInfo ' for passing the value
Dim si2 as struct_CustInfo ' for getting the value


Call that function
si1.strCustName = "some name"
si1.intCustAge = 99

si2 = GetCustInfo(si1)

after executing, si1 contains the data.
You can use it as si1.strCustName and so on
as usual

Hope this helps

With Regards,
Raghavendra Mudugal
Reply With Quote
  #3 (permalink)  
Old July 14th, 2005, 05:54 AM
Authorized User
 
Join Date: Jun 2005
Location: , , India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI

 n2 as struct_name

 n2 = FN("input1", "input2")


the function in the VC++ DLL returns a structure.

funciton in VC++ :

typedef struct struct_name
{
  char *var1;
  char *var2;
  char *var3;
  struct struct_name *next;
}struct_name;

char *FN(char *variable1,char *variable2)
{
  code...
   return struct_name;
}

which popsup the following error...
Bad DLL calling convension

so now how do i get the struct_name
Reply With Quote
  #4 (permalink)  
Old July 15th, 2005, 06:32 AM
Friend of Wrox
Points: 687, Level: 9
Points: 687, Level: 9 Points: 687, Level: 9 Points: 687, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamilnadu, India.
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello sruti

Check this link
http://in.geocities.com/raghavendra_mudugal/cpp.zip

Unzip the file, you will find some files of c++.
Open the cpp2.cpp file to see the source code.
This is written in vc++ editor (c++ code). complie
it and run it you will see the output of the struct.

Theres a class and it has a public method which takes
a stuct as in param and gives struct as a out param.

check this and let me know. And try to recompile the
vc++ dll to this new way and check in the VB.

Hope this helps.

With Regards,
Raghavendra Mudugal
Reply With Quote
  #5 (permalink)  
Old July 15th, 2005, 01:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in your C code, FN is returning a struct_name function, but it is declared as a string (char *)
Be careful, VB is not friend with C methods returning structures. It is better to pass the structure (by ref) as a parameter of the method itself:

void FN(char *variable1,char *variable2, struct_char *p)

Second, the declaration of the VB udt (struct_CustInfo) does not match the defintion of the C structure.
And in any way, the parameters of the C structure are pointers, that VB does not know how to handle. What are you trying to accomplish with this? Maybe there are better solutions.

Marco
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code to read the structure & data of an excel alam1 Excel VBA 0 April 24th, 2007 11:39 PM
How to Pass c++ object across ATL DLL ann123 Visual C++ 0 January 30th, 2006 06:55 AM
urgent doubt between class & structure lgeetha C# 5 February 24th, 2005 09:27 AM
how to pass address of an array to a dll(in c++) iceman1188 General .NET 0 May 30th, 2004 09:19 PM
DLL & Excel - keep having to reset DLL reference! James Diamond Pro VB 6 2 May 25th, 2004 03:37 AM



All times are GMT -4. The time now is 03:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.