.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Marshal Nested Stucture using PInvoke

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :.NET Framework


I am using C# in a VisualStudio 2008 environment and
have to retrieve data from a 3rd party DLL written in C.
I can access all but two of the C functions successfully.
Both of these functions require a nested structure
to be passed, so the structure can be populated with data.

// supplied C structure
typedef  struct
   float  fPeak;
   float  fMean;
   float  fStd; 
   int    iNoPeaks;
    float  fArea;
    float  fPeak;
    float  fMean;
    float  fStd; 
    int    iNoSubpeaks;
      float  fArea;   
      float  fPeak;   
      float  fMean;   
      float  fStd;    
typedef  pcs_distr_info *  p_pcs_distr_info;
// supplied C prototype
int Analysis(
  pcs_handle hPcsObject        // handle
  p_pcs_distr_info  pPeaksInfo // problem with this line

// part of, example C code supplied
pcs_distr_info  DistrInfo;
int result = Analysis( hPcsObject, &DistrInfo );
//C# attempt at retrieving data from the DLL function

 public static extern int Analysis(System.IntPtr handle, 
                                   out DistrInfo distributionInfo);

// structure in C#
public const int PCS_MAX_NO_PEAKS     = 20;
public const int

View Complete Post

More Related Resource Links

Binding Nested Listviews in MVC ViewPage


I am a longtime .NET developer but for big applications and services.  This is my first asp.net project and I have chosen MVC.   I have a need for nesting a ListView within a ListView.  In this simple catalog app, I have EF 4 Entities that are Categories, SubCategories, ItemTypes, and Items.

My goal is to display a 5 column layout of SubCategories with their ItemTypes below them in a ViewPage.  I did just fine with it done out in C# as server directives such as:

    var subcats = Model.SubCategory.ToArray();
    var nrSubCats = subcats.Count();
    var rows = (nrSubCats/5) + (((nrSubCats % 5) > 0) ? 1 : 0);
    for (var row = 0; row < rows; row++)
    { %>
        <div style="width: 100%; float: left; clear: right;">
        var start = row * 5;
        for (var i = start; (i < start + 5) && (i < nrSubCats); i++)
        var subcat = subcats[i];
            <div style="float: left; clear: right; width: 20%; margin-left: 5;">
                <h2> <%:subcat.Name%></h2>
                    foreach (var its in subcat.ItemType)

MVC2 issue - Stuck. Trying to create a cms with nested partials


I am currently trying to display multiple items on a single page. I am not sure as to how to tackle this. What I have is a database table that has all the page data in. I have this run as a PagesController and this works fine. However what I would like to do is, if say the Products page is selected via the menu, I want to pull back not only the Products page html but also get all the products, and even be able to pull them through via category. I was trying to use a partial view, but I can't get it to work. The same would be for other pages, having partial views to display the other content, ie if Gallery is selected, the page html for Gallery shows and it then can push to a partial view that pulls all the gallery images from the gallery db table and so on. 

Maybe I am tackling this the wrong way. I have the pages stored in the db to allow for a CMS system I have setup. Maybe I need to use models for all the other items(Products, Gallery, Videos and such) and use the partial for the page html?

Any help would be greatly appreciated as I am confused.

Nested Tracers - is there a way to only log the outer trace?



I have some nested tracers. The outer one has a category of 'PageTrace' and the inner ones have categories of 'DBTrace'. When I set the outer category source to 'All' I get both traces. When I switch on the inner trace, I just get the inner trace.

So, my question: is there any way to just log the outer trace events, i.e. the Page Traces.




LDAP nested groups filter


Hi all,

In my organization we use nested groups.

For a particular usage, we have a group (let's assume that the group name "kuku"), and the names of all the nested groups under it contains "kuku" as well.

We may assume that no other group in the LDAP has "kuku" in the name.

I need to create a filter which will return all the users which belong to one of the "kuku"s group.

Obviously, using this filter will bring only the head kukus

(&(&(objectclass=user)(objectclass=person))(memberOf=CN=kuku,cn=.rest of the group DN.))

How can I use wild card to fetch all users which belong to any kuku?

For example: (&(&(objectclass=user)(objectclass=person))(memberOf=CN=.*kuku.*))



Editable multiple nested gridview


Greetings everyone,

I've got this page where I display a 3 level nested gridview. First gridview displays data, 2nd one displays data based on the 1st one's row and 3rd one displays data based on the 2nd gridview. All of this works perfectly, including the edit mode for the 3rd gridview. 

The issue comes when I make each gridview collapsible, again, it works fine but when I click on "Edit" on the 3rd gridview all the grids collapse, I can then re-open them and the "edit mode" is still present and I can still save my updated data. But that collapsing thing is quite annoying.

I based a lot of my code from this page: http://www.codeproject.com/KB/webforms/EditNestedGridView.aspx

And I understand how I can fix my issue on a 2 level nested gridview, by simply adding the C# code:

protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
            GridView gvTemp = (GridView)sender;
            gvUniqueID = gvTemp.UniqueID;
            gvEditIndex = e.NewEditIndex;

This makes allows me to save the index and prevent it from collapsing when I'm editing. Unfortunately, because I'm actually editing the 3rd gridview, if I code:

Create databound nested ajax toolkit accordion programatically(In code Behind)


Can anyone guide me in the right direction or give an example of How I would accomplish this?


I have  this so far but kind of stuck on how to do it programtically if I'm using header and content templates 

I have a xmldatasource.. In a nutshell at what point in my code do I need to create a new accordion? does it need to be

in the item_databound handler?


Imports Microsoft.VisualBasic

Public Class AccordionTemplate
    Implements System.Web.UI.ITemplate

    Dim templateType As String

    Sub New(ByVal type As String)
        templateType = type
    End Sub

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) _
          Implements System.Web.UI.ITemplate.InstantiateIn

        Dim ph As New PlaceHolder()

        Select Case (templateType)
            Case "Header"
                Dim myLabel As Label = New Label()
                myLabel.Text = "Test"
            Case "Content"
                ph.Controls.Add(New LiteralControl("<p>hello</p>"))
        End Select
    End Sub

End Class



Partial Class Accordion
    Inherits System.Web.UI.Page


How can i access my nested info?


I have a web service that returns information about master projects. Within the return i also get all of the sub project information. I have been using the Applications definition designer to create the ADF. It all works fine accept i cannot access the sup project information in any of the BDC web parts. All i get under the "Projects" variable is BDC.ProjectData[].

How can I access this data? I am using the standard SharePoint BDC web parts.

I have edited the XSL to dump out the xml being send and can see that instead of the projects section containing the expected information it says BDC.ProjectData[] along with another variable ___serializedId. So i suspect its an issue with my ADF but i am completly stuck.

Here is a sample of the web service return

    <MasterProjectTitle>PB test 1</MasterProjectTitle>
    <SupplierId />
    <Country />
    <MasterProjectClass>SNG Vehicle</MasterProjectClass>
    <IncoTerms />

Display a nested child ListView on PostBack while using DataPager on parent ListView


Hello ASP.NET community,

I am having trouble finding how to solve the following issue :

I am using nested listviews to display Sales and Sales details.

The main ListView displays General Information about Sales and the child ListView displays the detailed information about one sale. the child listview is shown only when the user clicks on a link (see included code, DataBind is made on PageLoad) :

ASPX Markup Code :

<asp:listview id="lvSales" runat="server" onitemdatabound="lvSales_ItemDataBound">
<table cellspacing="0" border="1" width="250" style="border-collapse:collapse;">
<tr runat="server" id="headerRow">
<th scope="col" style="width:30px;"></th>
<th scope="col">SaleNumber</th>
<tr id="itemPlaceHolder" runat="server" enableviewstate="true"/>
<tr id="row" runat="server">
<td style="text-align:center;"><asp:button id="btnShowHideDetails" runat="server" oncommand=&qu

Nested listview fk-problem with insert



My problem is this, i have a nested listview that works fine but if i need to do an insert and the nested listview dont have retrived any values (that is no posts created) i cant get hold of the fk that i need. If i put a hiddenfield in the parents listview with the fk how can i find it in codebehind when i do an insert? 



Local Report - nested objects



I trying to use Object data source for my local report. But the problem is that the datasource is having nested objects and I am not able to access the properties of the nested object.

I tried using =Fields!HomeAddress.Value.Zip as mentioned on this site


but couldn't get it working. Its returns #Error for this field.

I am using visual studio 2010 for developing this report

Please help.






Using an Application Resource in Nested UserControl

Hello This problem has been niggling me for months and I just can't seem to get to the bottom of it. I have a UserControl, let's call it 'UC_List', and the ListBox in it uses a Style which I have declared in my Application.xaml file. When working with UC_List.xaml everything seems fine. I then place 'UC_List' into a UserControl, let's call it 'UC_Summary'. I have declared the namespace at the top of UC_Summary.xaml. The xaml code in UC_Summary now has an Error: Could not create an instance of type 'UC_Summary'. Now I cannot see anything in the Design window, only a warning saying 'Problem Loading, the document contains errors that must be fixed...' However when I run the application everything works fine! After a lot of trial and error I found that the cause of the problem seems to be the Style referenced in the Application.xaml. If I declare the Style in UserControl.Resources at the top of UC_List the error goes away and the graphics in UC_Summary return. I've so far duplicated my Styles into individual UserControls to work around the problem but this could easily lead to inconsistancies. If anyone can suggest anything I would be really pleased to try it. Thank you. Regards Chris

pinvoke / kernel32.dll questions

To date, I have only run my .NET app on X86 boxes.  I would like to run it on Win2008 X64 but am concerned about my use of pinvoke to make kernel32.dll calls. Here are the kernel32.dll calls that I currently use in my app:   [DllImport("kernel32.dll")] static extern void OutputDebugString(string lpOutputString); //used for handling internal exceptions [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr GetModuleHandle(string moduleName); DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [PreserveSig] private static extern int GetModuleFileName([In] IntPtr hModule, [Out] StringBuilder lpFilename, [In][MarshalAs(UnmanagedType.U4)] int nSize); [DllImport("kernel32.dll")] private static extern int GetCurrentThreadId(); [DllImport("kernel32.dll")] private static extern int GetCurrentProcessId();   Will these same calls still work on an X64 OS (my App is compiled as AnyCPU)?  Do i need to use different kernel calls when running in 64 bit mode?   thanks      

Can I marshal the same object to two URIs?

Due to external constraints, I have to provide remoting access to the same Singleton object through two URI's. Omitting all the remoting configuration (which does seem to set up correctly), the general idea is: m_RemotedComponent = new RemotedComponent(); RemotingServices.Marshal(m_RemotedComponent, remotingName1); RemotingServices.Marshal(m_RemotedComponent, remotingName2); The two connections provide different interfaces that the one component supports and are accessed by different clients. Regardless of the order in which the two Marshal statements appear, the first one works and the second one doesn't. Upon attempting to connect to the second URI (regardless of whether I have an active connection to the first URI) using Activator.GetObject(...), I get the error message saying that the object has to derive from MarshalByRefObject. But, since I can always instantiate the first-listed URI successfully, it obviously does derive from that. If I create a second RemotedComponent, I can marshal it successfully to the second URI, so the problem is clearly related to trying to marshal the same object to two URI's. Is this supposed to be possible? If so, how?

Nested Work Flows in 4.0 Framework

Hi, I want to Invoke an work flow within an workflow. And I should be able to sqlTrack the inner workflow.  


hi all i have problem of using Marshal functions, i have the following .h declarations : typedef struct CPS_InfosCarte { UINT8 IdEmetteur [11]; UINT8 IdCarteLog [10]; UINT8 CategorieCarte [2]; UINT8 DateEmis [8]; UINT8 DateFinVal [8]; } CPS_InfosCarte ; UINT16 API_ENTRY CPS_InformationsCarte( UINT16 NumSession, struct CPS_InfosCarte PTR pIC, struct CPS_StatusService PTR pStatusService, PUINT16 pEtatCarte); That i had declared in vb.net as :   <StructLayout(LayoutKind.Sequential, Pack:=4)> _ Private Structure CPS_InfosCarte <MarshalAs(UnmanagedType.ByValArray, sizeconst:=11)> Dim IdEmetteur() As Byte <MarshalAs(UnmanagedType.ByValArray, sizeconst:=10)> Dim IdCarteLog() As Byte <MarshalAs(UnmanagedType.ByValArray, sizeconst:=2)> Dim CategorieCarte() As Byte <MarshalAs(UnmanagedType.ByValArray, sizeconst:=8)> Dim DateEmis() As Byte <MarshalAs(UnmanagedType.ByValArray, sizeconst:=8)> Dim DateFinVal() As Byte End Structure <DllImport("K:\cpsw32.dll" , EntryPoint:="CPS_InformationsCarte" , SetLastError:=True )> _ Private Shared Function CPS_InformationsCarte(ByVal NumSession As UInt16, B
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend