Click here to Skip to main content
15,905,616 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to Allow only numbers for TextBox Pin
Abhijit Jana24-Jun-08 23:01
professionalAbhijit Jana24-Jun-08 23:01 
AnswerRe: How to Allow only numbers for TextBox Pin
Mbah Dhaim25-Jun-08 4:21
Mbah Dhaim25-Jun-08 4:21 
QuestionCustom validator error: PropertiesValid throws object reference Pin
livez24-Jun-08 21:44
livez24-Jun-08 21:44 
AnswerRe: Custom validator error: PropertiesValid throws object reference Pin
leppie24-Jun-08 22:02
leppie24-Jun-08 22:02 
QuestionHow i can create a wizard dll Pin
wasimsharp24-Jun-08 21:23
wasimsharp24-Jun-08 21:23 
AnswerRe: How i can create a wizard dll Pin
Christian Graus24-Jun-08 21:44
protectorChristian Graus24-Jun-08 21:44 
GeneralRe: How i can create a wizard dll Pin
wasimsharp24-Jun-08 22:49
wasimsharp24-Jun-08 22:49 
Questiondeleting a file from local disk after putting in DB Pin
laziale24-Jun-08 21:18
laziale24-Jun-08 21:18 
AnswerRe: deleting a file from local disk after putting in DB Pin
Giorgi Dalakishvili24-Jun-08 21:23
mentorGiorgi Dalakishvili24-Jun-08 21:23 
AnswerRe: deleting a file from local disk after putting in DB Pin
wasimsharp24-Jun-08 21:24
wasimsharp24-Jun-08 21:24 
GeneralRe: deleting a file from local disk after putting in DB Pin
laziale24-Jun-08 21:36
laziale24-Jun-08 21:36 
GeneralRe: deleting a file from local disk after putting in DB Pin
laziale24-Jun-08 21:56
laziale24-Jun-08 21:56 
GeneralRe: deleting a file from local disk after putting in DB Pin
wasimsharp24-Jun-08 22:30
wasimsharp24-Jun-08 22:30 
GeneralRe: deleting a file from local disk after putting in DB Pin
Giorgi Dalakishvili24-Jun-08 22:00
mentorGiorgi Dalakishvili24-Jun-08 22:00 
AnswerRe: deleting a file from local disk after putting in DB Pin
leppie24-Jun-08 21:57
leppie24-Jun-08 21:57 
Questiondistributed computing?? Pin
Camilo Sanchez24-Jun-08 20:25
Camilo Sanchez24-Jun-08 20:25 
AnswerRe: distributed computing?? Pin
Marek Grzenkowicz24-Jun-08 22:49
Marek Grzenkowicz24-Jun-08 22:49 
GeneralRe: distributed computing?? Pin
Camilo Sanchez25-Jun-08 16:53
Camilo Sanchez25-Jun-08 16:53 
GeneralRe: distributed computing?? Pin
Marek Grzenkowicz26-Jun-08 1:07
Marek Grzenkowicz26-Jun-08 1:07 
QuestionUSP Implemenation Pin
sher_azam24-Jun-08 20:22
sher_azam24-Jun-08 20:22 
AnswerRe: USP Implemenation Pin
Ashfield24-Jun-08 21:14
Ashfield24-Jun-08 21:14 
QuestionCannot marshal 'return value': Pointers cannot reference marshaled structures? Pin
cristi_alonso24-Jun-08 20:18
cristi_alonso24-Jun-08 20:18 
<pre>--------------------------------------------------------------------------------

I wrote code to access structre from C# .net where structure is in C dll .here are the two files .when i debug the code i got runtime exception i.e MarshalDirectiveException saying that Cannot marshal 'return value': Pointers cannot reference marshaled structures. Use ByRef instead.


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

[MarshalAs (UnmanagedType.ByValArray,SizeConst=5)]
public unsafe fixed char abc[5];

}





// strucure DLL

[DllImport("StructureDisplay.dll")]

public static unsafe extern Detail * Disp();

static void Main(string[] args)

{

unsafe

{

Detail * var = Disp();//Cannot marshal 'return value': Pointers cannot reference marshaled structures. Use ByRef instead.


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

}

}

}


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


Can anyone help me out to solve this problem?what i need to do to solve this problem?

Any help appreciated.
Thanks in advance.</pre>
AnswerRe: Cannot marshal 'return value': Pointers cannot reference marshaled structures? Pin
leppie24-Jun-08 22:42
leppie24-Jun-08 22:42 
Questionconnect network PC Pin
Rinki Mukheraji24-Jun-08 19:38
Rinki Mukheraji24-Jun-08 19:38 
AnswerRe: Duplicate Post : Cp Member Please Ignore Pin
Abhijit Jana24-Jun-08 21:43
professionalAbhijit Jana24-Jun-08 21:43 

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.