I was talking to Rick Engle from Microsoft this evening about the DMProcessConfig managed wrapper code I posted before. He needed to get the results of a param-query out from the function into managed code and the previous code I posted doesn’t cut it. This code will pull the string return value out and hand it back to the caller rather than just destroy the buffer.

 

(Disclaimer applies)

 

unsafe static public string ProcessXMLWithResults(string Filename)

{

      string results = string.Empty;

      StreamReader sr = new StreamReader(Filename, Encoding.ASCII);

      string XML = sr.ReadToEnd(); 

// Test string: "<wap-provisioningdoc> <characteristic type=\"SecurityPolicy\"><parm-query name=\"4111\" /> <parm-query name=\"4112\" /> <parm-query name=\"4113\" /> <parm-query name=\"4115\" /> <parm-query name=\"4119\" /> <parm-query name=\"4120\" /> </characteristic></wap-provisioningdoc>";

      fixed (int * OutPtr = new int[1])

      {

            IntPtr outptr = (IntPtr)OutPtr;

            try

            {

                  int result = DMProcessConfigXML(XML, 1,outptr);

                  if (result !=0)

                  {

                        MessageBox.Show("Failed");

                  }

                  else

                  {

                        char *outbuffer = (char *)*OutPtr;

                        StringBuilder sb = new StringBuilder();

                        for (int count=0;outbuffer[count] != '\0';count++)

                        {

                              sb.Append(outbuffer[count]);

                        }

                        results = sb.ToString();

                        free(*OutPtr);

                  }

            }

            catch(Exception e)

            {

                  MessageBox.Show(e.Message);

            }

      }

      return results;

}

 

Marcus