B
Blip
The title of this is part of my problem. I'm a hobbiest programmer -
playing w/ c# now for a little more than a year. The generic problem
that stops me most often has to do with passing parameters between
windows forms & their related classes. The number of "cannot resolve
symbol" whatever drives me crazy at times.
I'm fairly comfortable w/ private/public/etc modifiers -- my confusion
seems to me more basic than that. I have a terrible time populating
controls on a form w/ info from the realted class -- seems like I have
to jump through all sorts of hoops to get it to work(sometimes).
Are there some general rules of thumb for how experienced folks go
about doing this?
for example:
namespace Tester
public class Netstuff {
public static bool GetMyAdaptersInfo(out IP_ADAPTER_INFO info)
{
int outBufLen = 0;
IntPtr pAdapterInfo = IntPtr.Zero;
int ret = 0;
try
{
ret = GetAdaptersInfo(pAdapterInfo, ref outBufLen);
// Allocate enough memory to hold the IP_ADAPTER_INFO
data.
pAdapterInfo =
CustomMarshal.AllocHLocal((uint)outBufLen); //uint
ret = GetAdaptersInfo(pAdapterInfo, ref outBufLen);
// ret will be zero if successful
if (ret != 0)
{
// The call to GetAdaptersInfo failed.
info = null;
return false;
}
else
{
// Success! Create a new instance of the
IP_ADAPTER_INFO structure with the data from the memory buffer.
info = new IP_ADAPTER_INFO(pAdapterInfo);
}
}
finally
{
// Free up any allocated memory.
CustomMarshal.FreeHLocal(pAdapterInfo);
}
// Call to GetAdaptersInfo was successful so return true.
return true;
}
}
Form1:
namespace Tester
public Netstuff n; {
public Form1() {
invoker += new Netstuff.SpeedUpdateHandler(speed);
n = new Netstuff(this, invoker);
n.SpeedUpdate += new
InitializeComponent();
}
private void buttonDisplayStats_Click(object sender, EventArgs
e)
{
bool b = Netstuff.GetMyAdaptersInfo(out n.info); <---
if (b)
frm2.PrintToTextbox(n.info);
}
}
The arrow marks the only way I know to move things from the Netstuff
class to controls on my form. My understanding (which is wrong) is
that I should be able to use "n" - the instance of Netstuff to access
members & properties of the Netstuff class, but that rarely works.
For example, I can't get at pAdapterInfo from Form1 (as n.
pAdapterInfo) What the heck am I conceptually missing? And thanks for
taking the time toi read through & answer this.
Tom
playing w/ c# now for a little more than a year. The generic problem
that stops me most often has to do with passing parameters between
windows forms & their related classes. The number of "cannot resolve
symbol" whatever drives me crazy at times.
I'm fairly comfortable w/ private/public/etc modifiers -- my confusion
seems to me more basic than that. I have a terrible time populating
controls on a form w/ info from the realted class -- seems like I have
to jump through all sorts of hoops to get it to work(sometimes).
Are there some general rules of thumb for how experienced folks go
about doing this?
for example:
namespace Tester
public class Netstuff {
public static bool GetMyAdaptersInfo(out IP_ADAPTER_INFO info)
{
int outBufLen = 0;
IntPtr pAdapterInfo = IntPtr.Zero;
int ret = 0;
try
{
ret = GetAdaptersInfo(pAdapterInfo, ref outBufLen);
// Allocate enough memory to hold the IP_ADAPTER_INFO
data.
pAdapterInfo =
CustomMarshal.AllocHLocal((uint)outBufLen); //uint
ret = GetAdaptersInfo(pAdapterInfo, ref outBufLen);
// ret will be zero if successful
if (ret != 0)
{
// The call to GetAdaptersInfo failed.
info = null;
return false;
}
else
{
// Success! Create a new instance of the
IP_ADAPTER_INFO structure with the data from the memory buffer.
info = new IP_ADAPTER_INFO(pAdapterInfo);
}
}
finally
{
// Free up any allocated memory.
CustomMarshal.FreeHLocal(pAdapterInfo);
}
// Call to GetAdaptersInfo was successful so return true.
return true;
}
}
Form1:
namespace Tester
public Netstuff n; {
public Form1() {
invoker += new Netstuff.SpeedUpdateHandler(speed);
n = new Netstuff(this, invoker);
n.SpeedUpdate += new
InitializeComponent();
}
private void buttonDisplayStats_Click(object sender, EventArgs
e)
{
bool b = Netstuff.GetMyAdaptersInfo(out n.info); <---
if (b)
frm2.PrintToTextbox(n.info);
}
}
The arrow marks the only way I know to move things from the Netstuff
class to controls on my form. My understanding (which is wrong) is
that I should be able to use "n" - the instance of Netstuff to access
members & properties of the Netstuff class, but that rarely works.
For example, I can't get at pAdapterInfo from Form1 (as n.
pAdapterInfo) What the heck am I conceptually missing? And thanks for
taking the time toi read through & answer this.
Tom