Click here to Skip to main content
15,896,413 members
Home / Discussions / C#
   

C#

 
GeneralRe: GDI / Disposing of objects question Pin
Luc Pattyn24-Jun-08 0:37
sitebuilderLuc Pattyn24-Jun-08 0:37 
GeneralRe: GDI / Disposing of objects question Pin
Harvey Saayman24-Jun-08 0:39
Harvey Saayman24-Jun-08 0:39 
AnswerRe: GDI / Disposing of objects question Pin
Daniel Grunwald24-Jun-08 0:25
Daniel Grunwald24-Jun-08 0:25 
QuestionDateTimePicker select just date Pin
laziale23-Jun-08 23:02
laziale23-Jun-08 23:02 
AnswerRe: DateTimePicker select just date Pin
DaveyM6924-Jun-08 0:13
professionalDaveyM6924-Jun-08 0:13 
GeneralRe: DateTimePicker select just date Pin
laziale24-Jun-08 0:21
laziale24-Jun-08 0:21 
GeneralRe: DateTimePicker select just date Pin
PIEBALDconsult24-Jun-08 4:43
mvePIEBALDconsult24-Jun-08 4:43 
QuestionCannot take the address of, get the size of, or declare a pointer to a managed type? Pin
cristi_alonso23-Jun-08 22:47
cristi_alonso23-Jun-08 22:47 
I wrote code to access structre from C# .net where structure is in C dll .here are the two files .When i build i get the error message saying that "Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructureExample.Program.Detail')"

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

#include<iostream.h>

#include<conio.h>

#include<malloc.h>

#include<string.h>

extern "C"

{

typedef struct

{

char *fname;

char *lname;


char abc[5];

}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);


memset(ptr->abc, 0x00, 5);

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

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


strcpy(ptr->abc, "ABC");
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)]

public unsafe sbyte* fname;

public unsafe sbyte* lname;

public char[] arr;

}





// strucure DLL

[DllImport("StructureDisplay.dll")]

public static unsafe extern Detail * Disp();//here i get error

static void Main(string[] args)

{

unsafe

{

Detail * var = Disp();


string a = new string(var->fname);

string b = new string(var->lname);



string e = new string(var->abc);


}


Console.WriteLine("hello world");


Console.WriteLine(a);

Console.WriteLine(b);



Console.WriteLine(e);


Console.Read();

}

}

}


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

How to solve this problem?can anyone help me out?





Any help appreciated.
Thanks in advance. Smile | :)
AnswerRe: Cannot take the address of, get the size of, or declare a pointer to a managed type? Pin
leppie23-Jun-08 23:08
leppie23-Jun-08 23:08 
QuestionRe: Cannot take the address of, get the size of, or declare a pointer to a managed type? Pin
cristi_alonso24-Jun-08 1:29
cristi_alonso24-Jun-08 1:29 
AnswerRe: Cannot take the address of, get the size of, or declare a pointer to a managed type? Pin
leppie24-Jun-08 1:40
leppie24-Jun-08 1:40 
GeneralRe: Cannot take the address of, get the size of, or declare a pointer to a managed type? Pin
cristi_alonso24-Jun-08 2:02
cristi_alonso24-Jun-08 2:02 
AnswerRe: Cannot take the address of, get the size of, or declare a pointer to a managed type? Pin
Harvey Saayman23-Jun-08 23:40
Harvey Saayman23-Jun-08 23:40 
Questionpending \0 in string? Pin
George_George23-Jun-08 22:38
George_George23-Jun-08 22:38 
AnswerRe: pending \0 in string? Pin
leppie23-Jun-08 23:12
leppie23-Jun-08 23:12 
GeneralRe: pending \0 in string? Pin
George_George23-Jun-08 23:15
George_George23-Jun-08 23:15 
GeneralRe: pending \0 in string? Pin
leppie23-Jun-08 23:49
leppie23-Jun-08 23:49 
GeneralRe: pending \0 in string? Pin
George_George24-Jun-08 1:47
George_George24-Jun-08 1:47 
GeneralRe: pending \0 in string? Pin
Ennis Ray Lynch, Jr.24-Jun-08 2:50
Ennis Ray Lynch, Jr.24-Jun-08 2:50 
GeneralRe: pending \0 in string? Pin
George_George24-Jun-08 2:57
George_George24-Jun-08 2:57 
GeneralRe: pending \0 in string? Pin
leppie25-Jun-08 2:22
leppie25-Jun-08 2:22 
GeneralRe: pending \0 in string? Pin
George_George25-Jun-08 2:28
George_George25-Jun-08 2:28 
QuestionNetwork Pin
ellllllllie23-Jun-08 22:10
ellllllllie23-Jun-08 22:10 
AnswerRe: Network Pin
Christian Graus23-Jun-08 22:18
protectorChristian Graus23-Jun-08 22:18 
GeneralRe: Network Pin
ellllllllie23-Jun-08 22:45
ellllllllie23-Jun-08 22:45 

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.