|
I have a c++ code including a method as
parsefile( FILE * pfile);
I have exported this method in c++ in a dll. But In my c# code I want to use this method.
Thus, I have written the below code in the cs file.
[DllImport("main.dll")]
public extern static void parseFile( File pfiOriginal );
static void Main(string[] args)
{
/**** I don't know how to handle FILE * here because there is no FILE *
in c#. deneme.pqd is my file to be used by parsefile method.The
compiler gives error that File constructor takes no arguments.
*****/
File a = new File("deneme.pqd");
parseFile(a);
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
Please can you help me urgently about a method doing this.
|
|
|
|
|
I think the structure FILE and class File is complete different.
If you have a structure called FILE, then copy it to C#.
struct FILE
{
...
}
then try to use this code:
[DllImport("main.dll")]
public extern static void parseFile([MarshalAs(UnmanagedType.Struct)]FILE pfiOriginal );
|
|
|
|
|
I have no structure called FILE. It is a C File I/O. So it is a a FILE pointer such as FILE *fp.
What should I do then????
|
|
|
|
|
Just use the C# function to open file.
FileStream fileStream = new FileStream("myfile.bin", FileMode.Open);
BinaryReader binaryReader = new BinaryReader(fileStream);
int a = binaryReader.ReadInt32();
float b = binaryReader.ReadSingle();
...
binaryReader.Close();
fileStream.Close();
I'm not a fan of DLLImport. It is not so easy. It is easier to write the function again in C#.
|
|
|
|
|
But I have to use Dllimport (((
|
|
|
|
|
Try using IntPtr:
[DllImport("testcpp2.dll"]
private static extern void parseFile(IntPtr pFile);
using(FileStream fStream = new FileStream("test.bin", FileMode.Open))
{
parseFile(fStream.Handle);
}
and if it still not working, try to write a extra function for bridging between parseFile(FILE* file) and parseFile(string filename).
Something like this:
void parseFileWithFilename(string filename)
{
}
Then in C# you can give only the filename in string. It is easier.
|
|
|
|
|
by Luking @ the funtion name, i concluded that you are trying to parse the file. for that you can write your own funtion in C# right? Lot of samples are there in google.
|
|
|
|
|
dear friends,
please send me code to create a program which can display dynamic IP's of all the running client.
regards.
Pawan Mishra
MCA, MCP.NET, MCAD.NET
|
|
|
|
|
Is this the same question as in your thread in the .NET Framework board?
---
b { font-weight: normal; }
|
|
|
|
|
How do I create a DataSet from an XSD file. I’ve read about some “Generate DataSet” option in Visual Studio but I cant find it.
Does it exist external tools for this too?
_____________________________
...and justice for all
APe
|
|
|
|
|
See if this helps..
http://hacks.oreilly.com/pub/h/5157
http://aspnet.4guysfromrolla.com/articles/020806-1.aspx
|
|
|
|
|
hi,
Does anybody know where to get C# source code to create the fancy Office 2007 Toolbar Ribbon with the big round button?
|
|
|
|
|
I want to use the <include> XML directive to drag in how to use doumentation in to my code so that it ends up in in the Object Browser and Intellisense. I've had no problems doing that, but there is one thing that concerns me. I put the XML in an existing XML file, that already has XML data that's needed by the designer class. The XML <include> directive requires that I specify a file path, is there some way I can symbolise the file path -ideally I'd like to use the resource name <namespace>.<classname>.Resources.XMLData.
|
|
|
|
|
I have seen the guidelines(Code project - before 2 days) to export the data from datagrid to excel sheet in Web application. How to make up the same operation in windows application.
Jey
|
|
|
|
|
You can use the csv concept.
SqlConnection cn ;
SqlCommand cmd ;
string filename ;
SqlDataReader dr ;
System.Text.StringBuilder sb ;
private void Button1_Click(object sender, System.EventArgs e)
{
cn=newSqlConnection("server=localhost;uid=sa;pwd=;database=northwind");
filename = "products.csv";
cmd = new SqlCommand("select * from products ", cn);
cmd.Connection.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
sb = new System.Text.StringBuilder();
//For field Names
for(int i = 0 ;i< = dr.FieldCount - 1;i++)
{
if( i < (dr.FieldCount - 1) )
{
sb.Append("\t" + dr.GetName(i) + "\t" + ",");
}
else
{
sb.Append("\t" + dr.GetName(i) + "\t" + "\n");
}
}
//For field Values
while( dr.Read())
{
for(int i = 0 ;i<= dr.FieldCount - 1;i++)
{
if( i < (dr.FieldCount - 1) )
{
sb.Append("\t" + dr.GetValue(i) + "\t" + ",");
}
else
{
sb.Append("\t" + dr.GetValue(i) + "\t" + "\n");
}
}
}
dr.Close();
cn.Close();
Response.ContentType = "Application/x-msexcel";
Response.AddHeader ("content-disposition", "attachment; filename=" + filename ) ;
//Write the file directly to the HTTP output stream.
Response.Write(sb.ToString());
Response.End();
}
/****************************************************************************
private void btExport_Click(object sender, EventArgs e)
{
string strTemp = String.Empty;
dst = new DataSet();
dst.Tables.Add("UserTable");
string strConnection = "Data Source=QUEST03;Initial Catalog=UserDatabase;User ID=hari; Password=shriji;";
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlCommand cmd = new SqlCommand("Select * From UserTable",conn);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (StreamWriter sw = new StreamWriter("E:/Hari/Problem_Import_Export/Problem1/test.csv"))
{
for (int i = 0; i <= dr.FieldCount - 1; i++)
{
if (i < (dr.FieldCount - 1))
{
sb.Append("\t" + dr.GetName(i) + "\t" + ",");
strTemp = strTemp + "\t" + dr.GetName(i) + "\t" + ",";
}
else
{
sb.Append("\t" + dr.GetName(i) + "\t" + "\n");
strTemp = strTemp + "\t" + dr.GetName(i) + "\t" + "\n";
}
}
sw.WriteLine(strTemp);
//For field Values
strTemp = String.Empty;
while (dr.Read())
{
for (int i = 0; i <= dr.FieldCount - 1; i++)
{
if (i < (dr.FieldCount - 1))
{
sb.Append("\t" + dr.GetValue(i) + "\t" + ",");
strTemp = strTemp + "\t" + dr.GetValue(i) + "\t" + ",";
}
else
{
sb.Append("\t" + dr.GetValue(i) + "\t" + "\n");
strTemp = strTemp + "\t" + dr.GetValue(i) + "\t" + "\n";
}
}
sw.WriteLine(strTemp);
}
}
dr.Close();
conn.Close();
MessageBox.Show("Data Is Imported Successfully...Test.txt File is Created.");
}
|
|
|
|
|
using System;
using System.IO;
using System.Data;
using System.Windows.Forms;
namespace AzoControls.MyDataExport
{
public class AzoDataExportToXLS
{
private int rowCount = 0;
private int sheetCount = 1;
private System.IO.StreamWriter excelDoc;
const string endExcelXML = "";
const string startExcelXML = "<xml version="">\r\n<workbook "="" +
="" "xmlns="\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n"" xmlns ="\"urn:schemas-microsoft-com:office:office\"\r\n" "xmlns:x="\"urn:schemas-" microsoft-com:office:"="" "excel\"\r\n="" xmlns:ss="\"urn:schemas-microsoft-com:"" "office:spreadsheet\"="">\r\n <styles>\r\n " +
"\r\n " +
"<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" +
"\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" +
"\r\n <Protection/>\r\n \r\n " +
"\r\n <Font " +
"x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n \r\n " +
"\r\n <NumberFormat" +
" ss:Format=\"@\"/>\r\n \r\n \r\n <NumberFormat " +
"ss:Format=\"0.00\"/>\r\n \r\n " +
"\r\n <NumberFormat " +
"ss:Format=\"0\"/>\r\n \r\n \r\n <NumberFormat " +
"ss:Format=\"dd/mm/yyyy;@\"/>\r\n \r\n " +
"\r\n ";
private DataTable dtXLS;
private DataRow drXLS;
public AzoDataExportToXLS(DataTable parTableName)
{
//Parameter DataTable Object
this.dtXLS = parTableName;
}
public void ExportToXLS()
{
try
{
string strFileName = "File001";
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.InitialDirectory = Path.GetDirectoryName(strFileName);
saveDlg.FileName = Path.GetFileNameWithoutExtension(strFileName);
saveDlg.AddExtension = true;
saveDlg.Filter = "Windows Excel (*.xls)|*.xls";
if (saveDlg.ShowDialog() == DialogResult.OK)
{
try
{
this.exportToExcel(saveDlg.FileName.ToString());
//this.WriteDataToXLS(saveDlg.FileName.ToString());
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
return;
}
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
}
private void exportToExcel(string fileName)
{
excelDoc = new System.IO.StreamWriter(fileName);
excelDoc.Write(startExcelXML);
excelDoc.Write("<worksheet ss:name="\"DataPages"" +="" sheetcount.tostring().trim()="" "\"="">");
excelDoc.Write("");
excelDoc.Write("<row>");
for (int ic = 0; ic <= dtXLS.Columns.Count-1; ic++)
{
excelDoc.Write("<cell ss:styleid="\"BoldColumn\"">");
excelDoc.Write(dtXLS.Columns[ic].Caption.ToString());
excelDoc.Write("");
}
excelDoc.Write("");
for (int x = 0; x <= dtXLS.Rows.Count-1; x++)
{
rowCount++;
drXLS = dtXLS.Rows[x];
//if row > 64000 new page
if (rowCount == 64000)
{
rowCount = 0;
sheetCount++;
excelDoc.Write("");
excelDoc.Write(" ");
excelDoc.Write("<worksheet ss:name="\"Sheet"" +="" sheetcount="" "\"="">");
excelDoc.Write("");
}
excelDoc.Write("<row>"); //ID=" + rowCount + "
for (int y = 0; y < this.dtXLS.Columns.Count; y++)
{
System.Type cellType;
cellType = drXLS[y].GetType();
switch (cellType.ToString())
{
case "System.String":
string XLSParameter = drXLS[y].ToString();
XLSParameter = XLSParameter.Trim();
XLSParameter = XLSParameter.Replace("&", "&");
XLSParameter = XLSParameter.Replace(">", ">");
XLSParameter = XLSParameter.Replace("<", "<");
excelDoc.Write("<cell ss:styleid="\"StringLiteral\"">" +
"");
excelDoc.Write(XLSParameter);
excelDoc.Write("");
break;
case "System.DateTime":
DateTime XMLDate = (DateTime)drXLS[y];
string XMLDatetoString = ""; //Excel Converted Date
XMLDatetoString = XMLDate.Year.ToString() +
"-" +
(XMLDate.Month < 10 ? "0" +
XMLDate.Month.ToString() : XMLDate.Month.ToString()) +
"-" +
(XMLDate.Day < 10 ? "0" +
XMLDate.Day.ToString() : XMLDate.Day.ToString()) +
"T" +
(XMLDate.Hour < 10 ? "0" +
XMLDate.Hour.ToString() : XMLDate.Hour.ToString()) +
":" +
(XMLDate.Minute < 10 ? "0" +
XMLDate.Minute.ToString() : XMLDate.Minute.ToString()) +
":" +
(XMLDate.Second < 10 ? "0" +
XMLDate.Second.ToString() : XMLDate.Second.ToString()) +
".000";
excelDoc.Write("<cell ss:styleid="\"DateLiteral\"">" +
"");
excelDoc.Write(XMLDatetoString);
excelDoc.Write("");
break;
case "System.Boolean":
excelDoc.Write("<cell ss:styleid="\"StringLiteral\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.Byte":
excelDoc.Write("<cell ss:styleid="\"Integer\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.Decimal":
excelDoc.Write("<cell ss:styleid="\"Decimal\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.Double":
excelDoc.Write("<cell ss:styleid="\"Decimal\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.DBNull":
excelDoc.Write("<cell ss:styleid="\"StringLiteral\"">" +
"");
excelDoc.Write("");
excelDoc.Write("");
break;
default:
throw (new Exception(cellType.ToString() + " not handled."));
}
}
excelDoc.Write("");
}
excelDoc.Write("");
excelDoc.Write(" ");
excelDoc.Write(endExcelXML);
excelDoc.Close();
}
}
}
grandy
|
|
|
|
|
private void ExportData(string parType)
{
if (parType.ToUpper() == "XLS")
{
//Parse DataTable
AzoControls.MyDataExport.AzoDataExportToXLS ExportXLS = new AzoControls.MyDataExport.AzoDataExportToXLS(table);
ExportXLS.ExportToXLS();
}
}
grandy
|
|
|
|
|
Hi,
I need to display different UI controls based on the row in the same column. for eg.
DataGridCell(row1,col1) should have a combo box,
DataGridCell(row2,col1) should have a Textbox,
DataGridCell(row3,col1) should have a multiline Textbox,
DataGridCell(row4,col1) should have a Date Picker
I can placed the respective controls when ever user select the perticular cell. Now i need the controls to be visible all the time not only on selection.
Can anyone help me out in resolving this problem? I have a customized class which inherits the DataGridTextBoxColumn.
Regards,
Kais
|
|
|
|
|
Dear gurus,
I am de/serializing objects with Serializers (e.g. XmlSerializer). It works just fine.
But each time if I add any attribute to my classes which I serialize (let's say I update my class to a new version) , then the appropriate serializer is not able to deserialize my classes. This behaviour is clear to me of course.
But how can I improve this behaviour?
My Idea with deserializing is the following:
1) Extend the class which has to be de/serialized with a version-info-tag
2) Before deserializing, read the version-info first from file
3) Dependent on this version, decide which Version of the class to use for deserialization
4) Read the file (deserialize) now with the right class-version
Can somebody help me with this topic?
Thanks a lot in advance
-- modified at 3:59 Wednesday 5th July, 2006
|
|
|
|
|
Hello,
I am using MFC - ActiveX control in C# based windows application.
I am not able to debug the control with the C# application while it is possible with the MFC applcation.
I want to call a function on buttton click event of windows application.
The function is in ActiveX control.
I have given the path of the exe in control also enabled the Unmanaged debugging in Windows application, but when i start debug it doesn't populate the exe, instead it comes out and ready for debug again.
Is it possible to do so if yes then HOW.
Thanks.
Byee..
Gajesh
Pune(India
-- modified at 8:04 Wednesday 5th July, 2006
|
|
|
|
|
I want to apply certain commands on the asseblies after they will be placed in the GAC during installation.e-g Tlbexp Assembly1.dll or regasm Assembly1.dll.
Currently i am running the Setup from batch file that starts the setup.Now the Setup will install the assemblies on to the GAC and also copies them into the installation path.
But this is not a good pocedure to accomplish the task.
Is there any good alternative?
Regards
Kamran
Kamran
-- modified at 1:34 Wednesday 5th July, 2006
|
|
|
|
|
I need to code my application in 3 tier.
But i dont have exact idea what to do.
I know the concept well, but dont understand how should i proceed.
Can anyone help me,
it would be better if you can give me some code samples.(ofcource Dummy)
Happy coding
|
|
|
|
|
Just googling for it can give you some good links showing the concept. Anyway, try this codeproject article itself. The architecture is all there.
http://www.codeproject.com/csharp/three_tier_architecture.asp
There has to be more to life than just this
|
|
|
|
|
|
Okay, so I'm very new to C# (and to programming in general for that matter), but I've come across this idea of boxing and unboxing that seems completely odd. In my understanding, it is a shell game of sorts between a referenced type and a value type. It seems to me that this might save in resources, and that it is similar to casting in C, but it is unclear to me. If anyone could give a reason as to why someone would want to use this technique, I would be very grateful.
"If you really want something in this life, you have to work for it. Now, quiet! They're about to announce the lottery numbers..."
- Homer Simpson
|
|
|
|