Click here to Skip to main content
15,845,829 members
Home / Discussions / C#
   

C#

 
QuestionMake datagridview selected row invisible Pin
geralson22-May-13 2:41
geralson22-May-13 2:41 
AnswerRe: Make datagridview selected row invisible Pin
Richard MacCutchan22-May-13 3:42
mveRichard MacCutchan22-May-13 3:42 
GeneralRe: Make datagridview selected row invisible Pin
geralson22-May-13 4:32
geralson22-May-13 4:32 
QuestionExcel without excel Pin
caradri22-May-13 1:34
caradri22-May-13 1:34 
AnswerRe: Excel without excel Pin
Richard Deeming22-May-13 2:46
mveRichard Deeming22-May-13 2:46 
AnswerRe: Excel without excel Pin
PIEBALDconsult22-May-13 6:03
mvePIEBALDconsult22-May-13 6:03 
GeneralRe: Excel without excel Pin
caradri22-May-13 6:19
caradri22-May-13 6:19 
Question2D Array Managed and Unmanaged code Data Marshling Pin
Subhash Madhukar21-May-13 23:34
Subhash Madhukar21-May-13 23:34 
Hello Friends,
Thanks in Advance... I am using VS2012 ON WIN7 as my development tool.

I want to get data from C++ into my C# 2D arrays, Arrays are member of strucutre.
I am getting data fine in case of Single dimension arrays and basic data types.

Below is the sample code:-

I have a C# strcuture having 3-4, multidimensional array example.

[StructLayout(LayoutKind.Sequential)]
public struct CompMultiArray
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2 * 200)]
public int [,] tempVacData;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2 * 200)]
public int [,] tempFuncData;
};


Public void GetDataFromUnmanagedCode()
{
CompMultiArray cmpGetData = new CompMultiArray();
cmpGetData .tempVacData = new int[2, 200]; // Allocating or not allocating has no effect
cmpGetData .tempFuncData= new int[2, 200]; // Allocating or not allocating has no effect

CPPClass.FillData(ref cmpGetData);

}

C++ side
struct CompMultiArray
{
int tempVacData[2][200];
int tempFuncData[2][200];
};

void FillData(CompMultiArray& cmData)
{
for(int i =0; i< 2; ++i)
{
for(int j = 0; j < 200; ++j)
{
cmData.tempVacData[i][j] = 100;
cmData.tempFuncData[i][j] = 200;

}
}
}

If I see data in C# side after getting from unmanaged code in Windows->Memory (VS2012), I can see correct data in memory. GC Code to get memory address
GCHandle gch = GCHandle.Alloc(cmpGetData.tempVacData, GCHandleType.Pinned);
// Get a pointer to the array data...
IntPtr pArrayData = gch.AddrOfPinnedObject();
// Via the debugger's memory viewer, confirm
// that the data is laid in memory in sequence.
gch.Free();


But using indexing, i cannot get any data.
for(int i = 0; i < 2; ++i)
{
for(int j = 0; j < 200; ++j)
{
cmpGetData.tempVacData[i,j];
cmpGetData.tempFuncData[i,j]
}
}

please ignore, Dllimport etc. all things are working fine.
please guide me.

Thanks,
Subhash
AnswerRe: 2D Array Managed and Unmanaged code Data Marshling Pin
David Knechtges22-May-13 4:28
David Knechtges22-May-13 4:28 
QuestionQuestion about constructors of a class Pin
Arun kumar Gautam21-May-13 19:22
Arun kumar Gautam21-May-13 19:22 
AnswerRe: Question about constructors of a class Pin
PIEBALDconsult21-May-13 19:50
mvePIEBALDconsult21-May-13 19:50 
GeneralRe: Question about constructors of a class Pin
Arun kumar Gautam21-May-13 20:06
Arun kumar Gautam21-May-13 20:06 
AnswerRe: Question about constructors of a class Pin
Pete O'Hanlon21-May-13 21:21
subeditorPete O'Hanlon21-May-13 21:21 
GeneralRe: Question about constructors of a class Pin
Arun kumar Gautam21-May-13 21:43
Arun kumar Gautam21-May-13 21:43 
AnswerRe: Question about constructors of a class Pin
DaveyM6921-May-13 23:12
professionalDaveyM6921-May-13 23:12 
AnswerRe: Question about constructors of a class Pin
harold aptroot22-May-13 4:49
harold aptroot22-May-13 4:49 
QuestionSome Columns of DataGridView Wont Accept Values Pin
matt_1ca21-May-13 18:51
matt_1ca21-May-13 18:51 
AnswerRe: Some Columns of DataGridView Wont Accept Values Pin
matt_1ca21-May-13 19:30
matt_1ca21-May-13 19:30 
GeneralRe: Some Columns of DataGridView Wont Accept Values Pin
matt_1ca22-May-13 15:57
matt_1ca22-May-13 15:57 
GeneralRe: Some Columns of DataGridView Wont Accept Values Pin
matt_1ca22-May-13 16:11
matt_1ca22-May-13 16:11 
QuestionTo Throw or Not To Throw Pin
Kevin Marois21-May-13 13:39
professionalKevin Marois21-May-13 13:39 
AnswerRe: To Throw or Not To Throw Pin
Garth J Lancaster21-May-13 14:19
professionalGarth J Lancaster21-May-13 14:19 
AnswerRe: To Throw or Not To Throw Pin
SledgeHammer0121-May-13 14:37
SledgeHammer0121-May-13 14:37 
GeneralRe: To Throw or Not To Throw Pin
Kevin Marois21-May-13 14:40
professionalKevin Marois21-May-13 14:40 
GeneralRe: To Throw or Not To Throw Pin
SledgeHammer0121-May-13 15:31
SledgeHammer0121-May-13 15:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.