![]() |
| | #1 |
| Tha 1 Sick RAT Join Date: Dec 2003
Posts: 267
| Dynamic adding of Controls I'm still learning the VStudio Express 2008 IDE. I'm tired of outputing to console and now just adding (well trying to) controls dynamcally however this hasn't met with any success yet. The following is a piece of my code to which everything compiles with no warning but howevere the labels aren't showing: Code: private void Form1_Load(object sender, EventArgs e)
{
System.Windows.Forms.Label label1, label2;
HidD_GetHidGuid(ref tGuid);
deviceInfoSet = SetupDiGetClassDevs(ref tGuid, "USB", IntPtr.Zero, 0);
label1 = new Label();
label1.Location = new Point(10, 15);
label2 = new Label();
label2.Location = new Point(50, 15);
label1.AutoSize = true;
label1.Size = new Size(28, 40);
label1.Visible = true;
label2.AutoSize = true;
label2.Visible = true;
label1.Text = "Device Info Set = " + deviceInfoSet.ToString();
label2.Text = "HidGuid = " + tGuid.ToString();
this.Controls.Add(label1);
}
__________________ A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside |
| WDT is offline | |
| | #2 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 95
| Code: using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication14
{
public partial class Form1 : Form
{
private Label label1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.label1 = new Label();
this.label1.Location = new Point(10, 15);
this.label1.AutoSize = true;
this.label1.Size = new Size(28, 40);
this.label1.Text = "Device Info Set = blah";
this.Controls.Add(this.label1);
}
}
}
Edit: By the way, do you have something already at point 10, 15? If so you would have to consider the label's position in the form's z-order. Maybe call this.label1.BringToFront(); Last edited by theoobe; 04-21-2009 at 02:42 PM. |
| theoobe is offline | |
| | #3 |
| Tha 1 Sick RAT Join Date: Dec 2003
Posts: 267
| Thanks I just copied it over to a new form, but I now have another question. Given the following: Code: [DllImport("setupapi.dll", CharSet=CharSet.Auto, SetLastError = true)]
public static extern Boolean SetupDiEnumDeviceInterfaces(IntPtr hDevInfo, ref SP_DEVINFO_DATA devInfo,
ref Guid interfaceClassGuid, UInt32 memberIndex,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData);
Code: result = SetupDiEnumDeviceInterfaces(deviceInfoSet, 0, ref tGuid, MemberIndex, ref tDevInterfaceData); the type in argument 2 is defined as: Code: [StructLayout(LayoutKind.Sequential)]
public struct SP_DEVINFO_DATA
{
public uint cbSize;
public Guid ClassGuid;
public uint DevInst;
public ulong Reserved;
}
__________________ A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside |
| WDT is offline | |
| | #4 | |
| the hat of redundancy hat Join Date: Aug 2001 Location: Hannover, Germany
Posts: 2,769
| Quote:
__________________ hth -nv She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate." When in doubt, read the FAQ. Then ask a smart question. | |
| nvoigt is offline | |
| | #5 |
| Tha 1 Sick RAT Join Date: Dec 2003
Posts: 267
| I need to pass a null value instead as it is possible to do so according to msdn to be able to retrieve the information I want.
__________________ A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside |
| WDT is offline | |
| | #6 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 95
| I don't see why it would be possible. In your declaration it clearly states that value 2 is expecting a ref, and you're not doing so. You must change your declaration to: Code: public static extern bool SetupDiEnumDeviceInterfaces(IntPtr hDevInfo, IntPtr devInfo, ref Guid interfaceClassGuid,
UInt32 memberIndex, ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData);
Code: SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref tGuid, MemberIndex, ref tDevInterfaceData); Last edited by theoobe; 04-22-2009 at 08:03 AM. |
| theoobe is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ListView controls - Adding items .. What the beep? | IceDane | Windows Programming | 7 | 04-08-2008 12:07 PM |
| Adding a directory to a dynamic library path | vivharv | Windows Programming | 3 | 09-20-2007 07:09 AM |
| SVN Import Causes Crash | Tonto | Tech Board | 6 | 11-01-2006 03:44 PM |
| confused about adding controls to main window | terracota | Windows Programming | 4 | 11-24-2004 12:35 PM |
| I need help on adding tooltips to controls | Templario | Windows Programming | 6 | 01-03-2003 03:47 PM |