|
Thanks for your advice.
Steve
|
|
|
|
|
I have 2 sample structures in the unmanaged code(c++ dll)
typedef struct
{
char* lpszString1,
long ulField1;
}SubStruct;
typedef struct
{
int szlen;
SubStruct* arrsubstruct;
}arrstruct;
And I declare a method in the unmanaged dll
/*
*Method Structwithstructarray will print out the contents
* the members of the array sent from managed code and
* and reassign the array to point to a new set of element.
*/
void Structwithstructarray(arrstruct* mstruct)
{
cout << " Structwithstructarray "<< endl;
SubStruct* oldmanagedarray = mstruct->arrsubstruct;
for(int elem=0;elem<mstruct->szlen;elem++)
cout << oldmanagedarray[elem].lpszString1 << endl;
SubStruct* newunmanagedarray=new SubStruct[4];
newunmanagedarray[0].lpszString1="UnManaged0";
...
....
mstruct->szlen=4;
mstruct->arrsubstruct=newunmanagedarray;
}
The corresponding definitions in managed code
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
public struct submanagedStructure
{
public string sx;
public long szlen;
public submanagedStructure(string _sx,long _szlen)
{
sx=_sx;
szlen=_szlen;
}
}
structure 2:
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
public struct arrStructure
{
public int szlen;
public IntPtr mbuf;
}
[DllImport("........dll")]
public static extern int Structwithstructarray(ref arrStructure ama);
Now I invoke the function in the following sequence
//Populate structure members to send to unmanaged
submanagedStructure[] arrmanagedStructure = new submanagedStructure[3];
arrmanagedStructure[0]=new submanagedStructure("submanagedstructure1",15);
.....
....
arrStructure MyStruct = new arrStructure();
MyStruct.szlen=arrmanagedStructure.Length;
MyStruct.mbuf = Marshal.AllocCoTaskMem(
Marshal.SizeOf(arrmanagedStructure[0]) * arrmanagedStructure.Length
);
//Copy each structure into our allocated block
int iCurOffset = 0;
foreach(submanagedStructure item in arrmanagedStructure)
{
Marshal.StructureToPtr(
item,
(IntPtr)(MyStruct.mbuf.ToInt32() + iCurOffset) ,
false );
iCurOffset += Marshal.SizeOf(arrmanagedStructure[0]) ;
}
//Finally send to unmanaged module
Structwithstructarray(ref MyStruct);
//retrieve the returned structure elements
int outval = MyStruct.szlen;
IntPtr rudt=MyStruct.mbuf;
submanagedStructure[] recvmanagedarray = new submanagedStructure[outval];
for ( int i = 0 ; i < outval; i++ )
{
recvmanagedarray[i] = (submanagedStructure)Marshal.PtrToStructure (
(IntPtr )rudt, typeof ( submanagedStructure ) );
Console.WriteLine("The string element {0} of the struct {1} ",i,recvmanagedarray[i].sx );
rudt = (IntPtr)((int)rudt + Marshal.SizeOf ( typeof ( submanagedStructure ) ));
}
Now I find that just the 1 structure instance gets marshalled through the IntPtr into the unmanaged module.
So.in the unmanaged function
for(int elem=0;elem<mstruct->szlen;elem++)
cout << oldmanagedarray[elem].lpszString1 << endl;
It prints out the first structure and gives a null reference exception thereafter.(Why do the other 2 do not get marshalled?)
Similarly when the structure reference returns,the line "Console.WriteLine("The string element ....." prints out UnManaged0 and UnManaged2.
What happened to the structure elements UnManaged1 and UnManaged3?
Please advise.
|
|
|
|
|
|
How to export data from datagrid to excel?
Whats the command for that?
Anyone could help?
Thanx!
|
|
|
|
|
|
I've already read this article,but it doesn't help.
Any other suggestion?Thanx anyway!
|
|
|
|
|
This is my code:
void Button1Clicked(Object sender,System.EventArgs e)
{
Button a = (Button)FindControl("Button1");
a.Attributes.Add("OnClick","return confirm('Do you want to save?');");
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(GridView);
GridView.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
but it can't prompt out the alert page for you to save. How come?
Another problem,how to direct the page to a seperated excel page?
Can anyone pls correct it?Thanx so much!
|
|
|
|
|
|
is it possible to increment/decrement or such the datacolumn through the expression property?
|
|
|
|
|
hi,
Yes, It is possible to give features like auto numering in datacolumn.
Check the AutoIncrement property of datacolumn,expression etc.
Then use little bit logic
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
how can i do something like multiply all the values of a column by a constant through the expression property ?(not looping through the rows).
|
|
|
|
|
hi,
You can check DataColumn.Expression property for more information.
this is a small eg.
static void Main(string[] args)
{
DataTable Dtbl=new DataTable("MyTable");
Dtbl.Columns.Add(new DataColumn("Qty",typeof(Int32)));
Dtbl.Columns.Add(new DataColumn("Rate",typeof(Int32)));
Dtbl.Columns.Add(new DataColumn("Total",typeof(Int32),"Qty*Rate"));
for(int i=1;i<10;i++)
{
DataRow Dtr=Dtbl.NewRow();
Dtr["Qty"]=i*2;
Dtr["Rate"]=i+2;
Dtbl.Rows.Add(Dtr);
}
foreach(DataRow Dr in Dtbl.Rows)
{
Console.WriteLine(Dr["Total"].ToString()+"\n");
}
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
How can i write a program by C# which when i click a button in my program, Internet Explorer automatic choose a specify hyperlink in specify webpage. Do you have some sample to program with Internet Explorer 6?
Nothing
|
|
|
|
|
hi,
If you want to start external process in your C# application then you can go ahead with this
System.Diagnostics.Process.Start("www.codeproject.com");
this will open our site in your IE
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I have a dataset with two tables:
BookEntry <->> BookLines
I set "BookEntry" as Table for the dataview.
If I set the RowFilter property of the dataview, can I say:
BookEntryBookLines.Id = '0'
"Every rule in a world of bits and bytes can be bend or eventually be broken"
|
|
|
|
|
hi,
static void Main(string[] args)
{
DataSet Dset=new DataSet();
DataTable Dtbl=new DataTable("MyTable");
Dtbl.Columns.Add(new DataColumn("Qty",typeof(Int32)));
Dtbl.Columns.Add(new DataColumn("Rate",typeof(Int32)));
Dtbl.Columns.Add(new DataColumn("Total",typeof(Int32),"Qty*Rate"));
for(int i=1;i<10;i++)
{
DataRow Dtr=Dtbl.NewRow();
Dtr["Qty"]=i*2;
Dtr["Rate"]=i+2;
Dtbl.Rows.Add(Dtr);
}
foreach(DataRow Dr in Dtbl.Rows)
{
Console.WriteLine(Dr["Total"].ToString()+"\n");
}
Dset.Tables.Add(Dtbl);
DataView dv=new DataView();
dv.Table = Dset.Tables["MyTable"];
dv.AllowDelete = true;
dv.AllowEdit = true;
dv.AllowNew = true;
dv.RowFilter = "Qty = '16'";
dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
}
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Hi All,
I have a page with its height is 4 inch.
I need to print 7 lines of text per page.
Therefore, I must ensure that I can set the heigth
of text to 0.5 inch exactly.
Pease help me.
Thank you,
|
|
|
|
|
You can use Font constructor override to specify you want inches as units.
Font font = new Font("Arial", 7.0f, GraphicsUnit.Inch)
|
|
|
|
|
You wanted .5 inches height so it should be:
Font font = new Font("Arial", 0.5f, GraphicsUnit.Inch);
|
|
|
|
|
Thanks Werdna,
Please see comment in this suorce code.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;
namespace TestPrint
{
public class PrintingExample
{
private Font printFont;
public PrintingExample()
{
Printing();
}
public void Printing()
{
try
{
PrintDocument pd = new PrintDocument();
printFont = new Font("Arial", 0.78f,System.Drawing.GraphicsUnit.Inch);
pd.DefaultPageSettings.PaperSize= new PaperSize("MP", 826, 468);
pd.DefaultPageSettings.Margins = new Margins (78,78,78,78);
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
finally
{
}
}
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
float fontHeight = printFont.GetHeight(ev.Graphics);
linesPerPage = ev.MarginBounds.Height / fontHeight;
System.Console.Out.Write("MarginBounds.Height: " + ev.MarginBounds.Height.ToString() + "\n");
System.Console.Out.Write("Font Height : " + fontHeight.ToString() + "\n");
System.Console.Out.Write("Line(s) per Page : " + linesPerPage.ToString() + "\n\n");
while (count < linesPerPage && count < 4)
{
string s = count.ToString() + ":" + fontHeight.ToString() + "/" + ev.MarginBounds.Height.ToString();
yPos = topMargin + (count * fontHeight);
ev.Graphics.DrawString (s, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
ev.Graphics.DrawLine(new Pen(System.Drawing.Color.Black),leftMargin,yPos,leftMargin+400,yPos);
count++;
}
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawLine(new Pen(System.Drawing.Color.Black),leftMargin,yPos,leftMargin+400,yPos);
}
public static void Main(string[] args)
{
new PrintingExample();
}
}
}
Nghĩa - I2A4U Group
|
|
|
|
|
I want to create a tabcontrol that has his rows spread over the entire width of the control. I know there is a property SizeMode - FillToRight, but that seems to work only with multilines.
CAn anyone tell me how to create this tabcontrol?
|
|
|
|
|
Total guess - but would width="100%" work?
|
|
|
|
|
|
I have had lots of trouble setting up the code on the computer I work. The project is a web service. When I load it, I share the wwwroot directory, get that sorted. When i try to open the solution, I keep getting the message, "Cannot get folder information from the server".
what does that mean?
Thanks
|
|
|
|
|
hi,
Check Whether Your Created Virtual Directory For Your Application
**************************
S r e e j i t h N a i r
**************************
|
|
|
|