This is a technical one that is above me...
Ive got a custom class I made that uses a lot of external procedures from mpr.dll. Basically I get the values I need from them and put them into what use to be a struct and return the struct to the program that requires them. The struct is very simple... it contains to string properties.
The problem I am having is that when I take those strings and use them in just about anything (such as a database) the strings get corrupted somehow and the data is lost, this doesnt happen if I put it into a control that has a list collection such as a ListBox or ListView. I thought that maybe this was because I was passing it back via a struct, so I changed my struct that Im passing back into a class and the same problem occurs, so now Im wonder if rather than a static method I should be using a regular method. Below is an example of what is happening...
If the actual values returned by the procedure were:
TEST123
SOMEBODY
ANYTHING
FOUR
EXTERNAL
What would go into the database is the following:
TEST123
SOMEBOD
ANYTHIN
FOURHIN
EXTERNA
Notice that because the first return string was a length of 7, it truncated all other strings to 7 if they were longer, if they were less it appended the remaining letters from a previous value that has 7 characters.
Now if instead of the above procedure I was to have:
Everything would display proper on the control. And what this is the crap Im doing now to get things to work... I put everything into a hidden ListView and then from the ListView into a database... absolutely horrendous programming; I know this! And I want to fix it! - (update) Actually read my update below, only the next paragraph works, the above actually results in the same problem. (/update)
I also can move my DataAdapter.Update() method into the foreach loop, but that causes such large program lag that I rather just leave the horrendous programming to be honest with you.
This scope/reference problem Im having is driving me up the wall. Im willing to send the actually DLL that is doing this to someone who is knowledgable enough about using external procedures that use a lot of marshalling and memory management to fix the problem. This will be a great learning experience for me because Im lost on this one.
Thanks!
Ive got a custom class I made that uses a lot of external procedures from mpr.dll. Basically I get the values I need from them and put them into what use to be a struct and return the struct to the program that requires them. The struct is very simple... it contains to string properties.
The problem I am having is that when I take those strings and use them in just about anything (such as a database) the strings get corrupted somehow and the data is lost, this doesnt happen if I put it into a control that has a list collection such as a ListBox or ListView. I thought that maybe this was because I was passing it back via a struct, so I changed my struct that Im passing back into a class and the same problem occurs, so now Im wonder if rather than a static method I should be using a regular method. Below is an example of what is happening...
C#:
//MYTEST.DLL
//I put both the struct and the class... in actuallity its either one or the other...same with procedures
//I just wanted to show for example...
public strcut Demo1
{
public string ItemX;
public string ItemY;
}
public class Demo2
{
private string ix = "";
private string iy = "";
public string ItemX;
{
get { return ix; }
set { ix = value; }
}
public string ItemY;
{
get { return iy; }
set { iy = value; }
}
public Demo2()
{
//no initialization
}
}
public Class DoDemo
{
public Demo()
{
//no initialization
}
public static Demo1[] GetItems()
{
Demo1[] items;
//Code that does the external procedures and sets items
return items;
}
public static Demo2[] GetItems()
{
Demo2[] items;
//Code that does the external procedures and sets items
return items;
}
}
//The calling program looks like this:
public SomeProcedure()
{
Demo1[] d1 = DoDemo.GetItems();
foreach(Demo1 d in d1)
{
DataRow r = myTable.NewRow();
r[0] = d.ItemX;
r[1] = d.ItemY;
myTable.Rows.Add(r);
}
myDataAdapter.Update();
}
If the actual values returned by the procedure were:
TEST123
SOMEBODY
ANYTHING
FOUR
EXTERNAL
What would go into the database is the following:
TEST123
SOMEBOD
ANYTHIN
FOURHIN
EXTERNA
Notice that because the first return string was a length of 7, it truncated all other strings to 7 if they were longer, if they were less it appended the remaining letters from a previous value that has 7 characters.
Now if instead of the above procedure I was to have:
C#:
public SomeProcedure()
{
Demo1[] d1 = DoDemo.GetItems();
foreach(Demo1 d in d1)
{
myListView.Items.Add(d.ItemX);
myListView.Items[myListView.Items.Count - 1].Tag = d.ItemY;
}
}
Everything would display proper on the control. And what this is the crap Im doing now to get things to work... I put everything into a hidden ListView and then from the ListView into a database... absolutely horrendous programming; I know this! And I want to fix it! - (update) Actually read my update below, only the next paragraph works, the above actually results in the same problem. (/update)
I also can move my DataAdapter.Update() method into the foreach loop, but that causes such large program lag that I rather just leave the horrendous programming to be honest with you.
This scope/reference problem Im having is driving me up the wall. Im willing to send the actually DLL that is doing this to someone who is knowledgable enough about using external procedures that use a lot of marshalling and memory management to fix the problem. This will be a great learning experience for me because Im lost on this one.
Thanks!
Last edited by a moderator: