Click here to Skip to main content
15,890,947 members
Home / Discussions / C#
   

C#

 
GeneralRe: Google Speech Recognition Pin
Gerry Schmitz3-May-15 10:45
mveGerry Schmitz3-May-15 10:45 
Questioncode dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString() doesnt work Pin
aahamdan2-May-15 6:24
aahamdan2-May-15 6:24 
AnswerRe: code dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString() doesnt work Pin
OriginalGriff2-May-15 6:39
mveOriginalGriff2-May-15 6:39 
GeneralRe: code dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString() doesnt work Pin
aahamdan2-May-15 6:48
aahamdan2-May-15 6:48 
GeneralRe: code dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString() doesnt work Pin
OriginalGriff2-May-15 7:18
mveOriginalGriff2-May-15 7:18 
AnswerRe: code dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString() doesnt work Pin
Henrik Jonsson2-May-15 7:05
Henrik Jonsson2-May-15 7:05 
AnswerRe: code dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString() doesnt work Pin
V.4-May-15 22:58
professionalV.4-May-15 22:58 
QuestionHow can I write string to a memory mapped file? Pin
Member 116587422-May-15 0:52
Member 116587422-May-15 0:52 
I want to write a string to a memory mapped file. I have used Marshalling to achieve desired size of string. I am getting an exception when I try to write my structure which contains a string and an int. If I remove the string, The code runs successfully.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;
using System.IO.MemoryMappedFiles;

namespace ConsoleApplication25
{
    class Program
    {
        static void Main(string[] args)
        {
            MemoryCreate<MemWriter> SharedData = new MemoryCreate<MemWriter>();
            MemWriter MemWriterObj = new MemWriter();
            if (!SharedData.open()) return;
            MemWriterObj.f=10;
            MemWriterObj.mystring = "Test";
            SharedData.Writer = MemWriterObj;
            Console.ReadLine();
            SharedData.close();
        }
    }
    class MemoryCreate<T> where T:struct
    {
        MemoryMappedFile mmf;
        MemoryMappedViewAccessor accessor;
       public bool open()
        {
           try
           {
               mmf = MemoryMappedFile.CreateNew("Test", 100);
               accessor = mmf.CreateViewAccessor(0, 0);
               return true;
           }
           catch(Exception e)
           {
               Console.WriteLine(e.Message);
               return false;
           }
       }
           public void close()
           {
               accessor.Dispose();
               mmf.Dispose();
           }
        public T Writer
           {
               set
               {
                   try
                   {
                       accessor.Write<T>(0, ref value);
                   }
                   catch(Exception e)
                   {
                       Console.WriteLine(e.Message);
                   }
               }
           }
        }
    [StructLayout(LayoutKind.Sequential,Pack=1,CharSet=CharSet.Ansi)]
    struct MemWriter
    {
        public int f;
        [MarshalAs(UnmanagedType.ByValTStr,SizeConst=16)] public string mystring;
    }
}


[edit]Code block added - OriginalGriff[/edit]

modified 2-May-15 7:15am.

QuestionRe: How can I write string to a memory mapped file? Pin
Richard MacCutchan2-May-15 3:33
mveRichard MacCutchan2-May-15 3:33 
AnswerRe: How can I write string to a memory mapped file? Pin
Member 116587422-May-15 4:17
Member 116587422-May-15 4:17 
GeneralRe: How can I write string to a memory mapped file? Pin
Richard MacCutchan2-May-15 4:23
mveRichard MacCutchan2-May-15 4:23 
GeneralRe: How can I write string to a memory mapped file? Pin
Member 116587422-May-15 4:34
Member 116587422-May-15 4:34 
GeneralRe: How can I write string to a memory mapped file? Pin
Richard MacCutchan2-May-15 4:56
mveRichard MacCutchan2-May-15 4:56 
GeneralRe: How can I write string to a memory mapped file? Pin
Member 116587422-May-15 5:19
Member 116587422-May-15 5:19 
GeneralRe: How can I write string to a memory mapped file? Pin
Richard MacCutchan2-May-15 5:28
mveRichard MacCutchan2-May-15 5:28 
GeneralRe: How can I write string to a memory mapped file? Pin
OriginalGriff2-May-15 4:30
mveOriginalGriff2-May-15 4:30 
GeneralRe: How can I write string to a memory mapped file? Pin
Member 116587422-May-15 4:40
Member 116587422-May-15 4:40 
GeneralRe: How can I write string to a memory mapped file? Pin
OriginalGriff2-May-15 4:54
mveOriginalGriff2-May-15 4:54 
GeneralRe: How can I write string to a memory mapped file? Pin
Member 116587422-May-15 5:11
Member 116587422-May-15 5:11 
AnswerRe: How can I write string to a memory mapped file? Pin
Sascha Lefèvre2-May-15 5:25
professionalSascha Lefèvre2-May-15 5:25 
QuestionHelp me, I need a simple program examples. Pin
Member 114460801-May-15 20:55
Member 114460801-May-15 20:55 
AnswerRe: Help me, I need a simple program examples. Pin
OriginalGriff1-May-15 21:16
mveOriginalGriff1-May-15 21:16 
QuestionProblem in killing both Application.exe and launched process Extract.exe from Application.exe in multiple instances environment Pin
shivmymail1-May-15 19:02
shivmymail1-May-15 19:02 
AnswerRe: Problem in killing both Application.exe and launched process Extract.exe from Application.exe in multiple instances environment Pin
OriginalGriff1-May-15 19:34
mveOriginalGriff1-May-15 19:34 
GeneralRe: Problem in killing both Application.exe and launched process Extract.exe from Application.exe in multiple instances environment Pin
shivmymail1-May-15 19:40
shivmymail1-May-15 19:40 

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.