Skip to content

IntPtr in c#

hans

Asked Mar 26, 2006, 4:31 AM EST8 answers
Share
LinkedInX
Hi, im new in c# and id like to work with winmm.dll from windows. so i imported it this way: [DllImport("winmm.dll")] extern static int mciSendString(string command, IntPtr responseBuffer, int bufferLength, int nothing); which works fine for me. But now i want to read a string out of my responseBuffer and i dont know how to de-referncate. In good old "c" iwould have used the " * " operator, so plz tell me what to use/do in c#. thx yas stefan

8 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    Try using one of the Marshal class static methods

    string theString = Marshal.PtrToStringAnsi(ResponseBuffer);

    best,

    Mike G.

    0
  • 0
    thx, this was the solution. yas stefan
    0
  • 0
    Out of curioisty what are you making with winmm? I'm currently in the process of making a media player myself in C# using winmm. Are you working on something simalir?
    0
  • 0
    im working on a audio recorder. playing audio files works already. my aim is to program an application which, records radio sequences that are longer than a given time and have a signal strength stronger than a given limit. something like rec all pro from sagebrush.
    0
  • 0
    Ahhh, we have much different goals.
    0
  • 0
    I need to pass an array of strings as an IntPtr to interface with something that uses a DLL. How do I do this? I have tried many different ways using Marshals and other stuff. It does not seem to work. I get memory allocation problems or I have errors in my code. What can I do to fix my problem?
    0
  • 0
    try adding the keyword "ref" before the array name when you are calling the function.
    0
  • 0
    I tried using the ref, but I got an error.

    cannot convert from 'ref string[]' to 'System.IntPtr'

    I had something like this in my code.

    string[] myStringArray = { "one", "two", "three", "four" };
    function(ref myStringArray);

    Is that what you said to do? There has got to be more, but I am not sure what it is.
    0