Re: IntPtr marshal causes exception



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

.



Relevant Pages

  • Re: Perfomance problem while passing large data volumes via WMI
    ... There are inherent problems passing too much data that way. ... > the file is about 300 Mb) and we want to pass it to the client side. ... > //these methods are memory and time consuming. ... My provider consumes about 1,5 Gb of memory ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Arrays
    ... cannot use pointers. ... say that basically when you pass an array, you ARE passing a pointer. ... the memory allocated for the call stack is returned to the ... and any parameters become garbage in unused memory. ...
    (microsoft.public.vb.controls)
  • Re: new revision ada
    ... There seem to be two proposed solutions for the problem of passing ... of additional memory, too. ... But what if the exception that is being processed is of a direct ... result of a out of memory error? ...
    (comp.lang.ada)
  • which ram?
    ... yes and go buy xxx marked ram that would be most helpful - I can see PC3200 mentioned in aida, is all pc3200 memory the same, I assume I need another 512Mb stick. ... Memory Module Properties: ... CPU Properties: ... Always passing ...
    (uk.comp.homebuilt)
  • Re: Non-failure guarantied malloc/new
    ... Probably because memory is cheap and computers on which the programs made ... > give NULL pointers. ... > easier to handle in a while loop then doing some exception handling. ... > allocation which is guarrantied not to fail. ...
    (comp.lang.cpp)