VB Marshal problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Vincent Schmid (vschmid_at_polylog.ch)
Date: 05/06/04


Date: Thu, 6 May 2004 11:25:04 +0200

Hello,

I've declared a VB callback Sub which is called by an unmanaged DLL (code
below). The PData parameter is a pointer to a memory bloc which is allocated
and freed by the dll as necessary.

The RequestFunc should read a string pointed by PData, and replace it by
another one. The problem arises when the Sub tries to write the answer :
there is an error when calling Marshal.PtrToStringAnsi. (The RequestFunc is
not supposed to free the memory bloc pointed by PData)

What's wrong with the following code ? (note : the buffer is allocated for
sure, and is large enough)

Many thanks for comments,
Sincerely
Vincent

Sub RequestFunc(ByVal PData As IntPtr, ByVal DataSize As Int32)

  Dim Request As String
  Dim Answer As String

  Request = Marshal.PtrToStringAnsi(PData, DataSize)
  MsgBox(Request)
  Answer = "This is the answer"
  Marshal.StructureToPtr(Answer, PData, False)
End Sub



Relevant Pages

  • Re: Pocket PC - Pointer Crash
    ... PUSHORT pData; ... I'm de-referencing a pointer who's contents/values I can view without any ... problems in the memory watch window. ... int FOO ...
    (microsoft.public.pocketpc.developer)
  • Re: Windows CE 5.0 : embedded pointer parameters marshalling
    ... When you don't call MapPtrToProcess and you dereference pData you're not ... I have a stream driver with XXX_IOControl function. ... I passed the following struct pointer to ... I know that for embedded pointer I have to use MapPtrToProcess in this way ...
    (microsoft.public.windowsce.platbuilder)
  • void * C array to a Numpy array using Swig
    ... I have wrapped a C IO module using SWIG -> Python Module. ... Now a is the object which contains pointer to data of the image. ... get the data pointed by pdata). ...
    (comp.lang.python)
  • Re: void * C array to a Numpy array using Swig
    ... Now a is the object which contains pointer to data of the image. ... get the data pointed by pdata). ... In full scipy there are typemaps for numpy arrays in ... Typemaps can be a little confusing at first, but they do make your interface a bit nicer. ...
    (comp.lang.python)
  • Re: Need Help declaring parameter variables for DllImport for c-dl
    ... What you said about the nSize and nLength makes a lot of sense. ... right about the pointer to the encoded data pointed by a pointer in the Blob ... IntPtr pData = Marshal.AllocHGlobal; ...
    (microsoft.public.dotnet.languages.csharp)