|
Hi
I would like to define a struct with array of int
I define the struct as below
The problem is that when I want to get the size of the struct, i'm getting it without the array size
such as
sNDIS_802_16E_ACTIVE m_NDIS_802_16E_ACTIVE;
m_NDIS_802_16E_ACTIVE = new sNDIS_802_16E_ACTIVE(20,20);
int size = Marshal.SizeOf(m_NDIS_802_16E_ACTIVE);
public struct sNDIS_802_16E_ACTIVE
{
public UInt32 NaplistLength;
public UInt32[] Nap;
public UInt32 NsplistLength;
public UInt32[] Nsp;
public byte [] aaa;
public sNDIS_802_16E_ACTIVE(UInt32 maxNSP_NAPSize, UInt32 maxNSP_NAPsize)
{
Nap = new UInt32[maxNSP_NAPSize];
Nsp = new UInt32[maxNSP_NAPSize];
NaplistLength = 0;
NsplistLength = 0;
}
} ;
please advice
ronen
|
|
|
|
|
the size of
public struct sNDIS_802_16E_ACTIVE {
public UInt32 NaplistLength;
public UInt32[] Nap;
public UInt32 NsplistLength;
public UInt32[] Nsp;
public byte [] aaa;
}
is 20B on Win32, i.e. 4B for each of the two ints, and 4B for each of the 3 arrays (an array is just a reference, not the data; the data sits elsewhere).
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi
But I define the size of the array size in the constructor
Should the size of the member of the struct include array definitions?
Ronen
|
|
|
|
|
I don't understand your question.
In THAT struct, under Win32, each member takes 4 bytes, either for an int value, or for a reference. The size of the arrays themselves is irrelevant inside the struct, as they are separate objects.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
|
All -
I am looking for an easy solution to split a name field from another DB. I am converting data from on DB to another. In the source DB the name field is one field that is free form. Here are some examples of names:
John Smith
John E Smith
DR John E Smith
DR John Smith
In my db the name field is first and last name (separate fields).
Any suggestions?
As always thanks for your help!
sk
|
|
|
|
|
Its a tricky one because you have a number of possibilities, i.e. Title and middle names.
If this was a one of process I would use manual intervention, but would also have fields for title.
Do you want to retain the title anywhere? where should the middle name be included? I would put the middle name with the forename if I only had two fields (forename, surname)
Why don't you try something like...
void GetMeSomeNames(string fullname, out string forename, out string surname)
{
forename = surname = "";
string[] names = fullname.Split(' ', StringFormatOptions.RemoveEmptyEntries);
if(names.length == 0)
return;
if(names.length == 1)
{
forename = names[0];
return;
}
bool hasTitle = false;
switch(names[0].ToLowerInvarient())
{
case "dr":
hasTitle = true;
case "mr":
hasTitle = true;
}
for(int i = (hasTitle ? 1 : 0); i < names.length - 1; i++)
forename += names[i] + " ";
forename = forename.Trim();
surname = names[names.length-1];
}
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Essentially, it is a tough task. There may be names that just have a first and last or first, middle and last and it may contains salutations (Dr, Mr, Mrs, etc.) also. Writing a script to take care of all of these scenarios is really difficult. Just give it a try.
|
|
|
|
|
You need some sort of agreement on what is considered first name and what is considered last name.
You could also have the following eg:
John Smith Peeters
John Edward Smith
John Edward Smith Peeters
John Edward Smith-Peeters
John E. Smith-Peeters
...
You could filter Dr, DR, Mr, Ms, ... as a title and one letter words (with or without . like E or E.) can be considered firstnames, but I'm not sure if it's possible to have a 100% correct algorithm.
good luck.
|
|
|
|
|
I don't think it can be done without human intervention. At best you could put the last element in the last name field and everything else in the first name field. Then review any first names that contain a SPACE.
|
|
|
|
|
PIEBALDconsult wrote: At best you could put the last element in the last name field and everything else in the first name field.
That would yield a lot of problems where I live, as:
1) a lot of last names consist of two or three words, such as
"Miel De Schepper" and "Jan van der Spiegel" (first names are Miel/Jan); here you should at least check for "de", "van der" and "van de" (all possible capitalizations) and when they occur they are part of the last name.
2) first names could be composite ("Jean-Paulus") and last names could be composite ("Paulus-Beeldens"); now what when one of them is composite, the hyphen is missing, and the middle word of three could be a second half of the first name, or the first half of the last name (say "Jean Paulus Beeldens")?
I am 100% sure there isn't an algorithm that solves the problem, and IMO the best fit algorithm is very region dependent.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi,
I am displaying Word Document using Web Browser, its working fine but i just want to show the text of that Word file. But currently its showing the Text as well the MenuBar on the top. Is there any way to hide the toolBar and so it only shows the Text ?
|
|
|
|
|
Hi
I have a form that has text boxes and combos bound to fields in an object. When the user is using the form they have the option to apply some default values to some of the fields. I was hoping that I would just have to either update the control with the value or just update the field in the object. When I update the field in the object, the form will not refresh with the new values until another field on the form is changed. If I update the control, the field in the object does not update.
My way around this was to update both like this
case "LOGCERT_LEVEL_":
logginCertCombo.SelectedValue = newValue;
staff.LogCert = newValue;
break;
To me that is a bit ugly
Is there a way to do this automatically? My controls are bound like this
logginCertCombo.DataBindings.Add("SelectedValue", staff, "LogCert");
I've tried google and today it is not being my friend.
Many Thanks
The FoZ
|
|
|
|
|
Sound like you want to look at the .BindingContext for your Form in order to get the BindingManagerBase (which will get you a Property Manager versus a CurrencyManager because it looks like you are binding to a single business object) so that you can use .PullData() and .PushData() to sync your controls and DataSource ...
|
|
|
|
|
Thanks for you reply Gerry, but I'm not sure how to get this working. I've looked up the Currency and Property Manager Classes and where the classes contain the Push and Pull methods they are not visible.
I created a private CurrencyManager myFormCurrencyManager for my form and added
myFormCurrencyManager = (CurrencyManager)this.BindingContext[staff] after I bound the controls. This caused an invalid cast exception so I changed it all to a PropertyManager still with no luck.
Am I missing something else? Do you know of any decent examples?
Cheers
The FoZ
|
|
|
|
|
Sorry about that; didn't realize those methods were protected.
Here is a solution that works: use the DataBindings ReadValue and WriteValue methods; eg.
<pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
private TextBox fistNameTextBox =
new TextBox() { Location = new Point( 0, 0 ) };
private TextBox lastNameTextBox =
new TextBox() { Location = new Point( 0, 30 ) };
private Button readButtom = new Button() {
Location = new Point( 0, 70 ),
AutoSize = true,
Text = "Read from Source"
};
private Person aPerson = new Person();
public Form1() {
readButtom.Click += new EventHandler( readButtom_Click );
fistNameTextBox.DataBindings.Add( new Binding( "Text", aPerson, "FirstName" ) );
lastNameTextBox.DataBindings.Add( new Binding( "Text", aPerson, "LastName" ) );
this.Controls.AddRange( new Control[] {
fistNameTextBox, lastNameTextBox, readButtom } );
}
void readButtom_Click( object sender, EventArgs e ) {
aPerson.FirstName = "John";
aPerson.LastName = "Smith";
foreach ( Control control in this.FindForm().Controls ) {
if ( control is TextBox && control.DataBindings.Count > 0 )
control.DataBindings[ 0 ].ReadValue();
}
}
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new Form1() );
}
public class Person {
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
}</pre>
|
|
|
|
|
Thanks Gerry.
The foreach loop was exactly the thing I was after
foreach ( Control control in this.FindForm().Controls )
{ if ( control is TextBox && control.DataBindings.Count > 0 )
control.DataBindings[ 0 ].ReadValue(); }
Cheers
The FoZ
|
|
|
|
|
Hi Everyone,
I have placed a sample code below in which i need to type cast from struct to list<object>. In this below example how i can add emp1 to operation list
public struct Operation
{
public bool success;
public string msg;
public List<Object> ListTest;
}
public struct Emp
{
public int EmpID;
public string EmpName;
}
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public void Method1()
{
Emp emp1 = new Emp();
Operation op = new Operation();
emp1.EmpID = 1;
emp1.EmpName = "Manoj";
op.success = true;
op.msg = "pass";
op.ListTest.Add(emp1);
}
}
Regards,
Manowj
|
|
|
|
|
And your problem is?
Looking at it, you are getting a "object not set to an instance of an object" exception, I suspect. Try:
{
Emp emp1 = new Emp();
Operation op = new Operation();
op.ListText = new List<object>();
emp1.EmpID = 1;
emp1.EmpName = "Manoj";
op.success = true;
op.msg = "pass";
op.ListTest.Add(emp1);
}
Or, by preferance, convert it to a class and handle it's internals better yourself!
BTW: use <pre> and </pre> blocks to preserve your formatting in future. It isn't too bad with a tiny fragment like this, but later...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi,
Thanks for your response. how can this be converted to JSON using ExtJS, json serializer is not able to convert it.
Regards,
Manowj
modified on Thursday, November 5, 2009 7:14 AM
|
|
|
|
|
I wouldn't want to convert it to anorexic XML.
Edit your OP to correct the code, and reflect the JSON requirement - you may get a more helpful resonse.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hello,
I want to read and write in the notepad itself. I can write any text to notepad file but i can't able to read the text. Like if i have opened "sample.txt" file in notepad and i want to read the content of that file. Here is my sample code:
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "C:/Users/krinal/Desktop/1.txt";
notePad.StartInfo.UseShellExecute = false;
notePad.StartInfo.RedirectStandardOutput = true;
notePad.StartInfo.RedirectStandardInput = true;
notePad.Start();
notePad.WaitForInputIdle();
notepadhandle = notePad.MainWindowHandle;
//write text to notepad
SetForegroundWindow(notePad.MainWindowHandle);
SendKeys.SendWait("Testing");
using sendkeys() we can write to notepad, is there anything for reading?
Please help me out.
Thank you in advance.
|
|
|
|
|
Try to find the child window whose text you want (by using for example Spy++).
After that use:
int GetWindowText(HWND hWnd, LPTSTR lpString, int nMaxCount);
If this fails, you need to attach your main thread to the notepad ones.
Greetings
Covean
|
|
|
|
|
Thank you,
I understand GetWindowText() method but what child window means?
Actually i am developing Text_To_Speech application, need to read notepad content text.
So i think my child window will be notepad. And i get content of notepad and use them from my application.
|
|
|
|
|
The main wnd is the full window with titlebar, menu, statusbar and so on.
But you need the text from the child edit window.
On my system notepad has the following windows (used spy++):
+ Window 000C0B3E "Unbekannt - Editor" Notepad
|--- Window 001D0848 "" Edit <--- thats the window with the text you want
|--- Window 00140B54 "" msctls_statusbar32
Greetings
Covean
|
|
|
|