Just curious if anything has changed with Isolator supporting p/invoke.
I've been following the Microsoft naming guidelines for unmanaged code methods found
http://msdn.microsoft.com/en-us/library/btadwd4w(vs.80).aspx
The unit tests I have work fine, I'm just worried that once I start controlling the Windows dialer I'm going to run into a huge headache for performance of the tests along with needing the required hardware to be able to effectively test all the different scenarios.
Here's the class that handles wrapping all of the interop calls that I'm testing:
http://dotras.codeplex.com/SourceContro ... 273#241556
Here are the methods I'm trying to fake:
http://dotras.codeplex.com/SourceContro ... 273#241559
http://dotras.codeplex.com/SourceContro ... 273#427986
If this isn't supported in Isolator yet, perhaps this will demonstrate how p/invoke is being done in real world scenarios, rather than arbitrary snippets of code.
I was planning on faking out the p/invoke calls so that when it returns, it simply returns data I know won't change.
Here's a perfect example of what I'm talking about:
[DllImport("rasapi32.dll", CharSet = CharSet.Unicode)]
public static extern int RasEnumConnections(
[In, Out] IntPtr lpRasConn,
ref IntPtr lpCb,
ref IntPtr lpcConnections);
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public static ReadOnlyCollection<RasConnection> GetActiveConnections()
{
ReadOnlyCollection<RasConnection> retval = null;
int size = Marshal.SizeOf(typeof(NativeMethods.RASCONN));
IntPtr lpCb = new IntPtr(size);
IntPtr lpcConnections = IntPtr.Zero;
bool retry = false;
do
{
NativeMethods.RASCONN conn = new NativeMethods.RASCONN();
conn.size = size;
IntPtr pConnections = IntPtr.Zero;
try
{
pConnections = Marshal.AllocHGlobal(lpCb);
Marshal.StructureToPtr(conn, pConnections, true);
int ret = SafeNativeMethods.RasEnumConnections(pConnections, ref lpCb, ref lpcConnections);
if (ret == NativeMethods.ERROR_BUFFER_TOO_SMALL)
{
retry = true;
}
else if (ret == NativeMethods.SUCCESS)
{
retry = false;
NativeMethods.RASCONN[] connections = RasHelper.CreateArrayOfType<NativeMethods.RASCONN>(pConnections, size, lpcConnections.ToInt32());
RasConnection[] tempArray = null;
if (connections == null || connections.Length == 0)
{
tempArray = new RasConnection[0];
}
else
{
tempArray = new RasConnection[connections.Length];
for (int index = 0; index < connections.Length; index++)
{
NativeMethods.RASCONN current = connections[index];
RasConnection item = new RasConnection();
item.Handle = new RasHandle(current.handle);
item.EntryName = current.entryName;
item.Device = new RasDevice(current.deviceName, current.deviceType);
item.PhoneBook = current.phoneBook;
item.SubEntryId = current.subEntryId;
item.EntryId = current.entryId;
#if (WINXP || WINXPSP2 || WIN2K8)
item.ConnectionOptions = current.connectionOptions;
item.SessionId = current.sessionId;
#endif
#if (WIN2K8)
item.CorrelationId = current.correlationId;
#endif
tempArray[index] = item;
}
}
retval = new ReadOnlyCollection<RasConnection>(tempArray);
}
else
{
ThrowHelper.ThrowRasException(ret);
}
}
finally
{
if (pConnections != IntPtr.Zero)
{
Marshal.FreeHGlobal(pConnections);
}
}
}
while (retry);
return retval;
}