|
Try passing true to Marshal.STructureToPtr to make sure any possible existing structure is destroyed, otherwise this leads to memory leaks.
Also, a few things about CLS-compliance. Don't use unsigned types if you hope to port your code ever. You can use the signed types and marshal them as unsigned types, using UnmanagedType.U4 for an Int32 , for example. Yo also don't need to use "Attribute" when attributing members - it's implied.
Other than that, there's nothing else that could be null except your string members in MCI_OPEN_PARAMS , the last of which is optional according to the documentation. Everything else besides the IntPtr is a value type, which can't be null .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello Heath,
I've already tried to do do that (pass true to Marshal.STructureToPtr ).
Unfortunately, the problem persists, and when I pass true , the program crashes when it ends (JIT Dialog appears). It's strange...
I'm start to thinking the problem is in those Marshal functions.
|
|
|
|
|
Nope. I use them all the time. Interop in .NET is what I focus on primarily, just see my article on Java/.NET interop without using web services or remoting, right in the presentation layer.
So true is bad in this case (it would be necessary for repeat calls using the same allocated memory).
One thing, the DWORD_PTR should be an IntPtr , which gets marshalled as a UnmanagedType.SysInt automatically by the CLR. A DWORD_PTR uses the same bit-length as an integer on the target platform, i.e. 32-bits on a 32-bit processor, 64-bits on a 64-bit processor, etc. The rest are fine, but you should consider using CharSet=CharSet.Ansi in the StructureLayoutAttribute instead of marshalling the individual fields. Just makes it much easier to read.
Also, a lot of your consts are defined as ulong (aka UInt64 ). When you see LONG or ULONG in native API documentation, it's still a 32-bit integer. You might be getting some overflow problems.
Finally, your mciSendCommand should look like this:
[DllImport("winmm.dll")]
[return:MarshalAs(UnmanagedType.U4)]
private static extern int mciSendCommand(
[MarshalAs(UnmanagedType.U4)] int deviceID,
[MarshalAs(UnmanagedType.U4)] int msg,
[MarshalAs(UnmanagedType.U4)] int command,
IntPtr param); If you'll always be using this to send the MCI_OPEN_PARAMS structure, you can declare it as the following, or add the following as an overload:
[DllImport("winmm.dll")]
[return:MarshalAs(UnmanagedType.U4)]
private static extern int mciSendCommand(
[MarshalAs(UnmanagedType.U4)] int deviceID,
[MarshalAs(UnmanagedType.U4)] int msg,
[MarshalAs(UnmanagedType.U4)] int command,
ref MCI_OPEN_PARAMS);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct MCI_OPEN_PARAMS
{
public IntPtr callback;
[MarshalAs(UnmanagedType.U4)] public int deviceID;
public string deviceType;
public string elementName;
public string alias;
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The problem was in ulong data types, I've change them and now it works fine.
Thanks for your help.
Pedro
|
|
|
|
|
Heath Stewart wrote:
Also, a few things about CLS-compliance. Don't use unsigned types if you hope to port your code ever. You can use the signed types and marshal them as unsigned types, using UnmanagedType.U4 for an Int32, for example. Yo also don't need to use "Attribute" when attributing members - it's implied.
CLS complaince is only necessary on the external level. The runtime will work correctly with all .NET intristic types. CLS complaince gaurentees the code can be used by a .NET implemetation (read other language) that only implement the bare minimun language requirements as laid out in the EMCA spec (see JScript.NET for such an example).
top secret
|
|
|
|
|
Perhaps "portable" was the wrong choice of words, but that's what I was getting at.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How many times does this need to get repeated? ULONG in C/C++ == UInt32 in C#, your parameter is likely getting truncated.
top secret
|
|
|
|
|
Hi leppie,
Well... what can I say? You're right. It's the same error I did last time I post here. This time I wont forget.
Thanks leepie and thanks Heath four your time
Pedro
|
|
|
|
|
Hi,
I am using Listbox controls in C#. Items are need to move in between two or three listboxes.
Buttom used are ADD, ADD ALL, ReMOVE, REMOVE ALL.
Problem being faced is due to absence of itemdata property of listbox. I am using array
for saving IDs. When I move one item of listbox to other list box how can i move the ID from
one array list to another, so that the ist array shold remove the entry automatically ?
I have used a complete class and ARRAYLIST. But here I want to remove an item from a listbox
after binding it to an ArrayList with .Datasource property It is not allowing to delete
the item.
Please help me in this regard
abid
|
|
|
|
|
Hi,
I am using Microsoft Application Blocks for .NET. In which sqlhelper class is available to do different functions. What I need is the output parameter value ?
I do nt know how to get an output parameter value from sqlhelper.ExecuteNonQuery();
Normally we get the output parameter value by executing the nonquery of the sqlcommand.
waiting for a .NET guru response ..........
|
|
|
|
|
I don't know what do you mean by sqlhelper class but for ExecuteNonQuery , when you assign a Parameter to your SqlCommand as I told you in other thread , when you excute this function , output parameters fill automaticlly and you can get them.
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
Hi,
SQLHelpder class is given in "Data Access Application Block". This block sample code is availabe on
Microsoft MSDN. Why am I using this becuase of time saving. Useful overloads are available to do more in less time.
What I need in a form is the newly added IDs in a table. For example I wrote the following code
//This module will insert a new role in the tblRole table by calling the stored procedure uspRoleNew
SqlParameter[] arparam = new SqlParameter[9];
arparam[0] = new SqlParameter("@pRoleName",SqlDbType.VarChar, 50);
arparam[0].Value= mRoleName;
arparam[1] = new SqlParameter("@pRoleDesc", SqlDbType.VarChar,50);
arparam[1].Value= mRoleDescription;
.
.
. .
arparam[8] = new SqlParameter("@pRoleIDout", SqlDbType.Int);
arparam[8].Direction=ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsGeneral.conStr, "uspRoleNew", arparam);
int _RoleID;
_RoleID = (int)arparam[8].Value;
In paramerter[8] i want the newly added ID. But SqlHelper is not returning any value.
Below is the alternative solution for the above problem
mSqlCommand.Connection= _Sqlconn;
mSqlCommand.CommandText="uspRoleNew";
mSqlCommand.CommandType=CommandType.StoredProcedure;
mSqlCommand.Parameters.Add("@pRoleName",SqlDbType.VarChar, 50);
mSqlCommand.Parameters[0].Value=mRoleName;
mSqlCommand.Parameters.Add("@pRoleDesc", SqlDbType.VarChar,50);
mSqlCommand.Parameters[1].Value= mRoleDescription;
mSqlCommand.Parameters.Add("@pRoleIDout", SqlDbType.Int);
mSqlCommand.Parameters["@pRoleIDout"].Direction= ParameterDirection.Output;
_Sqlconn.Open();
mSqlCommand.ExecuteNonQuery();
mRoleID = (int)mSqlCommand.Parameters["@pRoleIDout"].Value;
return mRoleID;
QUESTION ????? is Why sqlhelper not doing this. If u r aware of "Data Access Application Block" plz reply.
|
|
|
|
|
Hi,
I want to refer the sqlparameter object to sqlcommand object. how can i do that ? I am giving different parameters input, return and output.
regards,
abid
|
|
|
|
|
abidkayani1 wrote:
I want to refer the sqlparameter object to sqlcommand object. how can i do that ?
See SqlCommand.Parameters property. There is an example in MSDN.
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
In addition to what Mazdak said about using the SqlCommand.Parameters dictionary to refer to parameters by name, it is faster and far better to save the params as variables when you add them and use those variables to refer to them later. No lookups in the Parameters dictionary are needed, then.
See the example[^] I wrote just yesterday.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi there ,
I have a question about the treeview control in .NET.
In my first form I create nodes dynamically.
In my second form I want to show the tree exactly like in the first form.
When I try to pass the treeview like this :
Form2 frm2 = new Form2();
frm2.treeView1 = this.treeView1;
I can see the nodes (when debugging and using quickwatch) of the new tree which are the same of the form1's tree.
The problem is that I cannot display them. Anyone to help me pls?
|
|
|
|
|
Your passing a reference to the first Treeview control, your not copying it. In fact, you CAN'T copy a Treeview control. The Nodes property of the Treeview is read only, so your are limited to recursively walking through the Nodes tree on your first Treeview and using the second Treeview's Add method to add the Nodes to the second tree.
RageInTheMachine9532
|
|
|
|
|
Hi All!!!
I want to show only the shape of my form which i specify e.g. i would liek to draw a form like triagle or in circle or any opolygon. How would i do that rest of the form becomes transparent and only this portion is shown?
Thanx in advance
sorry for my bad English.
|
|
|
|
|
You can start by reading up on non-rectangular forms here[^].
RageInTheMachine9532
|
|
|
|
|
i have the following code, this code will fetch me the http text only without the pictures so how can i get the pictures
<br />
WebProxy proxyObject = new WebProxy();<br />
<br />
proxyObject.BypassProxyOnLocal = true;<br />
GlobalProxySelection.Select = proxyObject;<br />
WebRequest req = WebRequest.Create(url);<br />
WebResponse result = req.GetResponse();<br />
Stream ReceiveStream = result.GetResponseStream( ) ;<br />
StreamReader sr = new StreamReader( ReceiveStream ) ;<br />
Char[] read = new Char[256];<br />
int count = sr.Read( read, 0, 256 );<br />
while ( count > 0 ) <br />
{<br />
String str = new String(read, 0, count);<br />
Response.Write(str);<br />
count = sr.Read(read, 0, 256);<br />
}<br />
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
Use regular expressions or complex string comparisons (obviously, the former is recommended) to find all supported attributes for linked content, such as SRC and HREF (in a LINK element, not an A element). If a BASE is in the header, be sure to resolve the URLs with that, otherwise use the current directory of the HTML document. Combine the absolute and relative paths (the Uri constructor does a good job of this, so see the Uri class documentation) and then download the content.
FYI, it may be much easier to read this into an IHTMLDocument2 and use MSHTML to save it for you, since it intrinsically knows all the linked content. See Reusing MSHTML[^] for more information. Experience with COM will be helpful.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How do you show properties of an object in a object collection editor,
eg. Panels collection???
|
|
|
|
|
You'll have to ellaborate a little on this...
Are you talking about DesignTime or RunTime?
Are you looking at extending the VS.NET Environment to include your own custom property UI Editor?
RageInTheMachine9532
|
|
|
|
|
How come this doesn't work? He doesn't save the data you edit in the datagrid
Thx in advance!
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{ //get the node out of the xml-file
string pad = "//school[@naam='" + comboBox1.SelectedItem.ToString() + "']";
XmlDocument xml = new XmlDocument();
xml.Load(@"c:\nodes.xml");
XmlNodeList contactNodes = xml.SelectNodes(pad);
string box = contactNodes.Item(0).OuterXml;
//write the node to a new file so it can be loaded into a dataset
xml.LoadXml(box);
XmlTextWriter xmltw = new XmlTextWriter(@"c:\testnodes.xml",new UTF8Encoding(false));
xml.WriteTo(xmltw);
xmltw.Close();
DataSet ds = new DataSet();
ds.ReadXml(@"c:\testnodes.xml");
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "school";
}
private void button1_Click(object sender, System.EventArgs e)
{
ds.WriteXml(@"c:\testnodes.xml");
}
|
|
|
|
|
Call dataGrid1.DataBind() function after setting DataSource property.
|
|
|
|