Re: IntPtr marshal causes exception
- From: MLM450@xxxxxxxxxxx
- Date: 31 Oct 2005 12:20:36 -0800
Thanks for the response, but I don't see how that is relevant here.
Perhaps you can elaborate? I am not passing around pointers or anything
like that. I am passing a handle to memory. Also, I don't get a chance
to do anything with the value passed to me. The exception occurs
somewhere between my C++ program and my C# program.
Peter Liu wrote:
> In C#, the memory is managed by GC, so the memory address is not fixed.
>
>
> <MLM450@xxxxxxxxxxx> ????
> news:1129832146.281862.86210@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >I am writing a C++ program that is using a C# control. It calls a
> > function that requires a handle to data in memory. If I set up the C#
> > function to take this parameter as a uint, it works fine. I would
> > rather set up the parameter as an IntPtr. But when I do that, I get an
> > exception when the C++ program calls the function.
> >
> > Any idea why the exception occurs?
> >
> > Thanks!
> >
> > C++ Code:
> > HANDLE MyData = GlobalAlloc(GMEM_MOVEABLE,File.GetLength());
> > LPVOID Mem = GlobalLock(MyData);
> > [... populate data ...]
> > GlobalUnlock(MyData);
> > MyControl->MyFunction((long)Data);
> > GlobalFree(MyData);
> >
> > C# Interface Function:
> > bool MyFunction(IntPtr hData);
> >
.
- Next by Date: Problems with a C# Listbox
- Next by thread: Problems with a C# Listbox
- Index(es):
Relevant Pages
|