Solved

passing structures from VC++/ MFC application to C# dll

Posted on 2007-11-21
9
283 Views
Last Modified: 2013-12-16
What is the best way of passing information from a VC+MFC application which will be calling C# dll to pass information.. what should be efficient some kind of binary structure or XML .. please notethat the data size is huge
0
Comment
Question by:pras_gupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20332358
what kind of information?
XML will be 100% safe but will be bigger than binary.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20332371
0
 
LVL 1

Author Comment

by:pras_gupta
ID: 20358940
Ok , i am using a bit similar approach now. I have two choices that either i pass an array of values to the C# component or call the class struct in c# component and populate that from the VC++. which way will be faster. Passing a array or populating a class struct in a loop in C#.
CClass:: RunXXX()
{
HRESULT hr = CoInitialize(NULL);
 
// create the interface pointer.
IManager pIRule(__uuidof(XXXBase));
 
//Call the method for populating input for processing
pIRule -> AddInputStructures(	long m_lProductId,
long m_lFieldId,
long m_lFieldValue,
string m_strType,
bool m_bDisabled, 
bool m_bEmpty,
bool m_bRequired);
pIRule ->GetOutPutVariables();
}
 vs 
i create and pass a array to the component 

Open in new window

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20359185
Passing array or class will have similar performance.

0
 
LVL 1

Author Comment

by:pras_gupta
ID: 20360530
I think i have make myself more clear now . Say I have a data of approximatly around 1000 numbers. I have two choices here.1
I loop thru all the 1000 values and populate a array in VC++ and pass it to the C# dll.
2. I loop thru 1000 values and populate the class in c# component and internally C# dll uses it. in this case i am making 1000 calls to the c# dll. like below code will be called 1000 times.
pIRule -> AddInputStructures(      long m_lProductId,
long m_lFieldId,
long m_lFieldValue,
string m_strType,
bool m_bDisabled,
bool m_bEmpty,
bool m_bRequired);
pIRule ->GetOutPutVariables();
}


In this scenario what do you think will be faster.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20360567
the 1000 calls will make your code significative slower than passing the entire array once.
0
 
LVL 1

Author Comment

by:pras_gupta
ID: 20360644
Thanks, what do you suggest is the best way to pass a array from VC++ to C# dll
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
ID: 20360722
just pass the pointer to the array.
0
 
LVL 1

Author Comment

by:pras_gupta
ID: 20366755
I am doing this now is there a better way


  double dFieldId[5]      = { 111111, 222222, 333333, 444444, 555555 } ;
 
      double dFieldValue[5] = { 100001, 200002, 300003, 400004, 500005 } ;
 
      double dType[5]   = { 0,1,0,1,0 } ;
 
      double dDisabled[5]     = { 1,0,1,0,1 } ;
 
 
 
      // Create an global instance for ISplitArrayPtr Interface 
 
      ISplitArrayPtr objSplitArray ;
 
      hr = objSplitArray.CreateInstance (__uuidof(CSplitArray)) ;
 
      
 
      long m_Size = 5 ; 
 
      objSplitArray->InitializeArray(m_Size) ;
 
 
 
      SAFEARRAY* sArrayId ;
 
      SAFEARRAY* sArrayValue ;
 
      SAFEARRAY* sArrayType; 
 
      SAFEARRAY* sArrayDisabled ; 
 
 
 
      
 
      SAFEARRAYBOUND sabounds[1];
 
      sabounds[0].lLbound = 0;
 
      sabounds[0].cElements = m_Size ;
 
      sArrayId = SafeArrayCreate(VT_R8, 1, sabounds);
 
      sArrayValue = SafeArrayCreate(VT_R8, 1, sabounds); 
 
      sArrayType = SafeArrayCreate(VT_R8, 1, sabounds);
 
      sArrayDisabled = SafeArrayCreate(VT_R8, 1, sabounds); 
 
      
 
      //if ( *sArrayId == NULL || *sArrayValue == NULL || *sArrayType == NULL || *sArrayDisabled == NULL )
 
      //    return E_OUTOFMEMORY;
 
      
 
      long lx[1] = {0L};      
 
      double dVal = 0 ;
 
      for ( long lIndex = 0 ; lIndex < m_Size ; lIndex++ )
 
      {
 
            lx[0] = lIndex;
 
                   
 
            HRESULT hr1 ;
 
 
 
            dVal = dFieldId[lIndex] ;           
 
            hr1 = ::SafeArrayPutElement(sArrayId, lx, &dVal);                                   
 
            dVal = dFieldValue[lIndex] ;        
 
            hr1 = ::SafeArrayPutElement(sArrayValue, lx, &dVal);                                      
 
            dVal = dType[lIndex] ;        
 
            hr1 = ::SafeArrayPutElement(sArrayType, lx, &dVal);                                       
 
            dVal = dDisabled[lIndex] ;          
 
            hr1 = ::SafeArrayPutElement(sArrayDisabled, lx, &dVal);                                   
 
      }
 
      
 
      objSplitArray->PopulateFields( sArrayId, sArrayValue, sArrayType, sArrayDisabled ) ;
 
      objSplitArray->DisplayFields() ;

Open in new window

0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

751 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