Click here to Skip to main content
15,923,087 members
Home / Discussions / C#
   

C#

 
GeneralRe: Do you prefer using Microsoft Enterprise Data Block over EF 6.0 Pin
Mycroft Holmes27-Jan-15 13:41
professionalMycroft Holmes27-Jan-15 13:41 
QuestionThe form appeared in debug mode even though I deleted it. Pin
WrightSfiso25-Jan-15 22:36
WrightSfiso25-Jan-15 22:36 
AnswerRe: The form appeared in debug mode even though I deleted it. Pin
OriginalGriff25-Jan-15 22:45
mveOriginalGriff25-Jan-15 22:45 
GeneralRe: The form appeared in debug mode even though I deleted it. Pin
WrightSfiso25-Jan-15 22:49
WrightSfiso25-Jan-15 22:49 
GeneralRe: The form appeared in debug mode even though I deleted it. Pin
OriginalGriff25-Jan-15 22:57
mveOriginalGriff25-Jan-15 22:57 
GeneralRe: The form appeared in debug mode even though I deleted it. Pin
WrightSfiso26-Jan-15 2:34
WrightSfiso26-Jan-15 2:34 
GeneralRe: The form appeared in debug mode even though I deleted it. Pin
OriginalGriff26-Jan-15 3:55
mveOriginalGriff26-Jan-15 3:55 
QuestionCustom properties OpenXml C# Pin
Member 1139687825-Jan-15 19:57
Member 1139687825-Jan-15 19:57 
AnswerRe: Custom properties OpenXml C# Pin
Richard Deeming26-Jan-15 2:19
mveRichard Deeming26-Jan-15 2:19 
Questioncrystal report problem Pin
shuaibwasifkhan25-Jan-15 10:31
shuaibwasifkhan25-Jan-15 10:31 
AnswerRe: crystal report problem Pin
Mycroft Holmes25-Jan-15 21:54
professionalMycroft Holmes25-Jan-15 21:54 
GeneralRe: crystal report problem Pin
BhavinPandya27-Jan-15 21:47
BhavinPandya27-Jan-15 21:47 
GeneralRe: crystal report problem Pin
Mycroft Holmes27-Jan-15 21:57
professionalMycroft Holmes27-Jan-15 21:57 
QuestionCross-platform Encryption / Decryption Pin
Jassim Rahma24-Jan-15 22:59
Jassim Rahma24-Jan-15 22:59 
AnswerRe: Cross-platform Encryption / Decryption Pin
Richard MacCutchan25-Jan-15 1:10
mveRichard MacCutchan25-Jan-15 1:10 
QuestionWhy doesn't my code find the .SelectedIndex? Pin
rfresh24-Jan-15 12:32
rfresh24-Jan-15 12:32 
AnswerRe: Why doesn't my code find the .SelectedIndex? Pin
BillWoodruff24-Jan-15 18:27
professionalBillWoodruff24-Jan-15 18:27 
AnswerRe: Why doesn't my code find the .SelectedIndex? Pin
OriginalGriff24-Jan-15 21:53
mveOriginalGriff24-Jan-15 21:53 
GeneralRe: Why doesn't my code find the .SelectedIndex? Pin
rfresh25-Jan-15 5:05
rfresh25-Jan-15 5:05 
GeneralRe: Why doesn't my code find the .SelectedIndex? Pin
OriginalGriff25-Jan-15 5:20
mveOriginalGriff25-Jan-15 5:20 
Questionhow to add a image to header of exportinf pdf in devexpress gridview Pin
Member 1064949524-Jan-15 11:04
Member 1064949524-Jan-15 11:04 
QuestionEncoding.ASCII.GetString(byte[]) and CR LF Pin
TMattC24-Jan-15 10:42
TMattC24-Jan-15 10:42 
AnswerRe: Encoding.ASCII.GetString(byte[]) and CR LF Pin
Richard Andrew x6424-Jan-15 16:32
professionalRichard Andrew x6424-Jan-15 16:32 
GeneralRe: Encoding.ASCII.GetString(byte[]) and CR LF Pin
TMattC25-Jan-15 1:32
TMattC25-Jan-15 1:32 
Questionmemory leak calling C functions in C# Pin
jpvi24-Jan-15 2:23
jpvi24-Jan-15 2:23 
I use C dll functions in C#. It works fine except I have a memory leak.

The first C function I use allocates memory (with malloc) and returns an array of string (char***) and the second one frees the memory (using free).

When I test those functions in a C program everything is ok - there are no memory leaks. However when I use those functions in a simple C# program using just thos functions I have a memory leak.

I 'm sure I'm doing something bad but I can't figure out what.

My code :
C#
[DllImport("TestERP.dll", CallingConvention = CallingConvention.StdCall)]
    private static extern int GetArray(string baseval,ref int nb,ref IntPtr array,IntPtr msg);

    [DllImport("TestERP.dll", CallingConvention = CallingConvention.StdCall)]
    private static extern int freeMemory( int nb, ref IntPtr array);


public static void GetManagedArray()
    {
         string[] tmp = new string[12];
         int nb = 0;
         IntPtr msg = Marshal.AllocHGlobal(256);
         string tmp2 = "";
         IntPtr intArr = IntPtr.Zero; 

         //call the C function which return the arry of string intArr
         GetArray("val",ref nb,  ref intArr,msg);

         //copy in managed string array
         for (int i = 0; i < nb; i++)
            tmp[i] = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(intArr, i * IntPtr.Size));

         tmp2 = Marshal.PtrToStringAnsi(msg);

         Marshal.FreeHGlobal(msg);

         //call the C function whiec free memory
         freeMemory(nb, ref intArr);

         intArr = IntPtr.Zero;

         GC.Collect();

    }

I add the code of C functions :
C++
int __stdcall GetArray(char base[],int* nb,char*** array,char* outmsg)
{
    int i =0;

    (*array) = (char**)calloc(12, sizeof(char*));

    for (i = 0; i < 12; i++)
    {
        (*array)[i] = calloc(256,sizeof(char));
        sprintf((*array)[i],"%s %d",base,i) ;
    }

    *nb= 12;

    strcpy(outmsg,"message erreur");

   return 0;
}

int __stdcall freeMemory(int nb,char*** array)
{
    int i =0;

    for (i = 0; i < nb; i++)
    {
        free((*array)[i]);
        (*array)[i] = NULL;
    }

    free((*array));

    *array = NULL;

    return 0;
}

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.