I have a problem in retreiving data using SAFEARRAYS,when I am sending data from Visual Basic application to C DLLs.
I have a typical situation as below
I have defined following structures in VisualBasic application

Type EmployeeBonus
    emp_Bonus as double
End type
Type EmployeeSalary
    emp_salary as double
    empbonus() as  EmployeeBonus
End type
Type employee
    emp_Number as double
    empsalary()as EmployeeSalary
end type

my_employee() as employee
'I am taking care of all structure memory management in VB application.
                      My Sample VB Code
I am sending Employee structure to c DLL by calling
Dll function say:
'Dll already defined in say emp.bas file
'dll returning long value
ret = EmployeeCalculation(hwnd as long,ByRef My_employee() as employee)
When I am sending this employee Nested structure to C Dll
program, I could only able to retrieve data up to first nested structure in c program.(employee to employeesalary )
But when I am going to 2nd(from employeesalary to employeebonus) nesting level it is giving
Junk value.(i.e Memory allocation for 2nd structure is not done)
This  metod described in VB dovumentation file c:\program file\visual basic\vb4dll.txt
                   My Sample C code
case 1: I ensure size of structures are same when sending   data from VB to C Dll
case 2: Even if their is any remote possiblity of size miss match(which I think next to impossible) I prevented it by using padding.
struct employeebonus {
    int emp_Bonus;
    int padding;
struct EmployeeSalary{
   int emp_salary ;
   int padding;
   SAFEARRAY FAR* empbonus;
struct employee{
    int emp_Number;
    int padding;
    SAFEARRAY FAR* empsalary;
/*****************************C Dll call*******************/
__declspec(dllexport)int EmployeeCalculation(HWND hwnd,LPSAFEARRAY FAR *p)
strct employee as temp;
struct employeeSalary as empsal;
struct employeebonus as empbonus;
//Say If I do any mathematical manuplation here I could get //it in VB application
empsal.emp_salary += empsal.emp_salary ;
//Here I am getting Junk(unintilized )values
/**************For Information***********/
I am using VC++4.0 compiler for dll.

                             With Regards


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Could it be related to the fact you are getting the element into empsal and then referencing it as tempsal? Or was that just a typo? (You could well have a tempsal somewhere else in your program that is being used without a compiler error).
ukoundinyaAuthor Commented:
I feel you are refferencing to the entier different situation.
Here when we use SafeArrays,and retrieve the element of
Safe Arrays it should be stored in temporary structures.
It is not for Syntax satisfaction......
                                                        Thanking You
Here, translated into VB, is what you are doing:

temp = employee(p)
empsal = temp.empsalary(j)
empbonus = tempsal.empbonus(j)

but - tempsal has never been initialized! It is NOT the same as empsal in the code you posted.

My point is, that the code you posted simply and obviously will not work. Either the bug I pointed out is the reason it doesn't work, or you posted the code with mistakes. If you don't post the code exactly as it is written the chances of finding why it fails are low.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

This is not an easy question, in fact, it's a very hard one.  Check out:

There are 5 articles that talk about writing DLLs for VB.  An explanation of SafeArrays is included.  In addition, each section contains a link that you can click to download sample source code (the download file is the same for all 5 articles).  You should be able to find your answer there.

ukoundinyaAuthor Commented:
Dear mrmick
I am very glad that you have suggested me good internet site.
   I have gone through the web documents.But they never suggested    how to solve for nested structures.
   Thanking You

How much do you expect for 50 points?  Common point values at Experts-Exchange are:

25: Very Easy
50: Easy
100: Medium
150: and up Hard

Do you think this is in the Easy catagory?
ukoundinyaAuthor Commented:
I am increasing the value of the question to 150.
I am interesed in the answer as i am facing very difficulty
in my project.
Thanking you
with regards

ukoundinya, in my earlier suggestion, article number 5 covers SafeArrays.

It's title is "The Safe OLE Way of Handling Arrays"; however, this isn't OLE, it's OLE's way - which is exactly the same as VB.  If you look a little closer, you'll find it has a complete explanation of how to use SafeArrays.  Take another look.

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
ukoundinya, I told you in the very first answer (which you rejected) why the code you *posted* doesn't work. If this isn't the problem, then you apparently don't want to post the actual code which is failing, and you don't want general references as to how to make safearrays work, so you might as well simply give up and stop wasting all our time. You can't ask for help then refuse to work with the people trying to help you.
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.