I need, to create a XmlDocument after accessing unmanaged code. When I do this the application stops without throwing any exception. What's the matter...
Thanks in advance.
/////////////////////////////////////////////////////////////
using System;
using System.Runtime.InteropServices;
namespace Error
{
class Class1 {
[DllImport("haspms32.dll", CallingConvention=CallingConvention.StdCall)]
static extern void hasp(int service, int seed, int lptnum, int pass1, int pass2, ref int p1, ref int p2, ref int p3,ref System.IntPtr p4);
[STAThread]
static void Main(string[] args) {
byte[] key = new byte[24];
System.Runtime.InteropServices.GCHandle ptrBuffer = System.Runtime.InteropServices.GCHandle.Alloc(key, System.Runtime.InteropServices.GCHandleType.Pinned);
System.IntPtr p4 = ptrBuffer.AddrOfPinnedObject();
int p1 = 0, p3 = 0;
int p2 = key.Length * 2;
hasp(50, 100, 0, 20941, 20261, ref p1, ref p2, ref p3, ref p4);
if(p3 == 0) {
p1 = 0;
p2 = key.Length;
hasp(61, 100, 0, 20941, 20261, ref p1, ref p2, ref p3, ref p4);
ptrBuffer.Free();
if(p3 != 0) {
Console.WriteLine("Error[" + p3 + "] al gestionar llave de seguridad.\n");
return;
}
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
xml.LoadXml("< xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\" ><LICENCIA><VERSION>1.1.2.0</VERSION><REVISION>05/2005</REVISION><INFORMACION><APLICACION><ID>1000</ID><NOMBRE>Servidor Operadora Virtual</NOMBRE><MODO>LICENCIA</MODO><CONCEPTOS><SERVIDORES>2</SERVIDORES><AGENTES>10</AGENTES></CONCEPTOS></APLICACION></INFORMACION></LICENCIA>");
xml = null;
Console.WriteLine("Pulsa una tecla.\n");
Console.ReadLine();
}
}
}
}

Permissions with unmanaged code.
Ashwin Purohit
Rick Strahl
2. I am wondering p4 given p4 is already a IntPtr, why do you need ref p4 as the parameter