Click here to Skip to main content
15,903,388 members
Home / Discussions / C#
   

C#

 
AnswerRe: popup calendar control from combo box Pin
rah_sin19-Jun-08 22:38
professionalrah_sin19-Jun-08 22:38 
GeneralRe: popup calendar control from combo box Pin
laziale19-Jun-08 22:48
laziale19-Jun-08 22:48 
GeneralRe: popup calendar control from combo box Pin
rah_sin19-Jun-08 22:51
professionalrah_sin19-Jun-08 22:51 
GeneralRe: popup calendar control from combo box Pin
laziale19-Jun-08 22:55
laziale19-Jun-08 22:55 
AnswerRe: popup calendar control from combo box Pin
Sathesh Sakthivel19-Jun-08 22:42
Sathesh Sakthivel19-Jun-08 22:42 
AnswerRe: popup calendar control from combo box Pin
Kjetil Svendsen20-Jun-08 3:59
Kjetil Svendsen20-Jun-08 3:59 
GeneralRe: popup calendar control from combo box Pin
laziale20-Jun-08 4:23
laziale20-Jun-08 4:23 
Questionproblem with returing structure ponter Pin
cristi_alonso19-Jun-08 22:22
cristi_alonso19-Jun-08 22:22 
<pre>I wrote code to access structre from C# .net where structure is in C dll .when i debug the code i got garbage value in the variables.
here are the two files .

------------------------- StrcutreDisplay.dll---------------------------------

#include<iostream.h>

#include<conio.h>

#include<malloc.h>

#include<string.h>

extern "C"

{

typedef struct

{

char *fname;

char *lname;

}Detail;




__declspec(dllexport) Detail * Disp()

{

Detail *ptr=(Detail *)malloc(sizeof(Detail));

ptr->fname = (char*)malloc(50);

memset(ptr->fname, 0x00, 50);

ptr->lname = (char*)malloc(50);

memset(ptr->lname, 0x00, 50);

strcpy(ptr->fname, "larson");

strcpy(ptr->lname, "scolari");

return ptr;

}

}


----------------------------StructureExample---------------------------------





using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

namespace StructureExample

{

class Program

{

[StructLayout(LayoutKind.Explicit)]

public struct Detail

{ // [MarshalAs(UnmanagedType.LPStr)]

[FieldOffset (10)]public unsafe char* fname;

[FieldOffset(10)]public unsafe char* lname;

}





// strucure DLL

[DllImport("StructureDisplay.dll")]

public static unsafe extern Detail * Disp();

static void Main(string[] args)

{

unsafe

{

Detail * var = Disp();

char* a = var->fname; //here i get garbage value and the value of this expression may be incorrect.it could not be evaluated because 'Cannot derefrence'(*var).fname' the pointer is not valid.

char* b = var->lname; // 'Cannot derefrence'(*var).lname' the pointer is not valid.


}


// IntPtr por = Disp();


//unsafe

//{

// Detail* ger;

// ger =(Detail )Marshal.PtrToStructure(por,typeof(Detail ));

//}

Console.WriteLine("hello world");

Console.Read();

}

}

}


------------------------------------------------------------------------------------------------

when i access that dll from c it works fine but through .net i get some garbage value.when i tried to convert char * to string by using a method of Marshal class (ptrToStringAuto() or ptrToStringAnsi())that time also i get some garbage value.My main question is why i am getting garbage value in char * a and char * b.






Any help appreciated.
Thanks in advance.</pre>
AnswerRe: problem with returing structure ponter Pin
Guffa19-Jun-08 23:05
Guffa19-Jun-08 23:05 
GeneralRe: problem with returing structure ponter Pin
cristi_alonso20-Jun-08 0:31
cristi_alonso20-Jun-08 0:31 
GeneralRe: problem with returing structure ponter Pin
Guffa20-Jun-08 13:45
Guffa20-Jun-08 13:45 
Questionhow to bind textbox to dataviewgrid Pin
ginji2019-Jun-08 21:15
ginji2019-Jun-08 21:15 
AnswerRe: how to bind textbox to dataviewgrid Pin
Shorgov19-Jun-08 21:40
Shorgov19-Jun-08 21:40 
GeneralRe: how to bind textbox to dataviewgrid Pin
ginji2019-Jun-08 22:16
ginji2019-Jun-08 22:16 
GeneralRe: how to bind textbox to dataviewgrid Pin
Shorgov19-Jun-08 22:19
Shorgov19-Jun-08 22:19 
GeneralRe: how to bind textbox to dataviewgrid Pin
Kjetil Svendsen20-Jun-08 4:08
Kjetil Svendsen20-Jun-08 4:08 
QuestionHow to assign Gridview cell value to a lable on "delete command"..? Pin
sacr8319-Jun-08 21:04
sacr8319-Jun-08 21:04 
AnswerRe: How to assign Gridview cell value to a lable on "delete command"..? Pin
paas20-Jun-08 1:37
paas20-Jun-08 1:37 
QuestionDataGrid item index Pin
grewin19-Jun-08 20:36
grewin19-Jun-08 20:36 
Questiongetting the mp3 file properties Pin
atanu_biswas19-Jun-08 20:09
atanu_biswas19-Jun-08 20:09 
Questionbinding textbox to datagridview Pin
ginji2019-Jun-08 20:01
ginji2019-Jun-08 20:01 
AnswerRe: binding textbox to datagridview Pin
paas20-Jun-08 1:42
paas20-Jun-08 1:42 
Questionlist<t> to array</t> Pin
cst_kvp19-Jun-08 19:01
cst_kvp19-Jun-08 19:01 
AnswerRe: list to array Pin
cst_kvp19-Jun-08 19:04
cst_kvp19-Jun-08 19:04 
AnswerRe: list to array Pin
N a v a n e e t h19-Jun-08 21:23
N a v a n e e t h19-Jun-08 21:23 

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.