|
See I want to make a bar that behaves like a splitter bar and yet leave no frames.For example I made a panel and dock it to the left.then a splitter bar docking to left.Then another panel dock set to fill.Now the problem is when i moved the splitter bar it leaves frames of itself(one trailing with the mouse and the other stayed back at the original position).But I don't want those frames.Is there any way to do this.
Thanks in advance.
just.starting...
|
|
|
|
|
Write your own splitter bar, or whenever the user is dragging the splitter, set the splitter position. FYI, there is a new splitter control in .NET 2.0 called a SplitContainer that supplants the current splitter control.
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|
Hi,
I'm using the P/Invoke mechanism to call an unmanaged C function, "CAPI_InitMaria", inside a 3rd party DLL. This function can be given a callback function, which is to be called during execution of CAPI_InitMaria.
Initially, this works fine: I can call the "CAPI_InitMaria" function from C#, after which the C# callback function (a delegate, see below) is called as well. Its argument (a GUID) also looks fine. However, after the callback method exits, I'm always getting an exception:
An unhandled exception of type 'System.NullReferenceException' occurred in MariaTestCSharp.exe
Additional information: Object reference not set to an instance of an object.
Doing the same in plain old C++ (VC++ 6.0) does not generate any problems. Also, if I specify 'null' instead of a callback function, everything works fine.
In C#, I call the CAPI_InitMaria function like this:
public class Form1 : System.Windows.Forms.Form
{
...
public delegate int OnStartCallback( ref Guid GUID );
private OnStartCallback myCallback;
[DllImport("Maria.dll")]
public static extern int CAPI_InitMaria( IntPtr hWndParent, IntPtr hResource,
OnStartCallback pInitFunction, int nFlags );
public static int OnStart( ref Guid GUID )
{
return 0;
}
private void initMaria_Click(object sender, System.EventArgs e)
{
System.Reflection.Module[] modules =
System.Reflection.Assembly.GetExecutingAssembly().GetModules(true);
instancePtr = Marshal.GetHINSTANCE( modules[0] );
myCallback = new OnStartCallback( OnStart );
CAPI_InitMaria( panel1.Handle, instancePtr, myCallback,
0x0004 );
}
...
}
The exported function and its associated callback types are declared like this in C++ (the procCAPI_InitMaria function is exported in the DLL as CAPI_InitMaria):
typedef int (*procCAPI_OnMariaStartup)( const GUID* pInstanceID );
typedef HWND(*procCAPI_InitMaria)( HWND hWndParent, HINSTANCE hResource,
procCAPI_OnMariaStartup pInitFunction, int nFlags );
Any ideas??
Thanks in advance,
Iwan Littel.
|
|
|
|
|
|
leppie, first of all thanks for your answer.
Regarding your solutions:
1) I already made the delegate instance static (see code in first post), so that solution didn't work
2) Currently, the delegate instance is stored inside a member variable of the Form1 class, which remains alive until the application shuts down. So wrapping the delegate instance in a GCHandle probably has no effect. Do you agree?
Thanks,
Iwan.
|
|
|
|
|
What leppie is referring to is the fact that the managed GC (garbage collector) can move things around, so that if your function calls your callback and it's moved, your unmanaged code (since it is unmanaged) does not know it and, most often, an AV (access violation) exception occurs, which bubbles up into the CLR which can throw a variety of exceptions.
Another problem that can occur is different calling conventions for functions. If that is the case, read one of my previous replies regarding that issue at http://www.codeproject.com/script/comments/forums.asp?msg=931771&forumid=1649#xx931771xx[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath, thanks for the reply.
I don't think my callback function is moved by the garbage collector, because it IS being called during the call to CAPI_InitMaria. The exception always occurs AFTER my callback function has been called and after it has exited successfully.
The calling convention issue was also my initial thought. However, I don't have any problems in VC++ (which uses the standard C++ calling convention). So I don't think I need to specify another calling convention in C#.
A colleague of mine came up with the following: It might be that the (3rd party) DLL we are calling starts up another thread, which calls the callback function (i.e. the C# delegate). Could this be the cause of the problem, and if so what could be done about it?
Thanks,
Iwan.
|
|
|
|
|
It could be, but you should still pin the delegate in memory. This is good practice for any reference type whether it's a problem or not now. This is really only necessary for long-lived delegates, however, since if you're passing the delegate to your native function only for that call you should be safe. The fact that you declared it as static also helps, but may not be the best design idea.
If the third-party DLL is creating a new thread (and you could find this out easily using Thread.Name or - lacking any names - store some test data in TLS (see Thread.AllocateNamedDataSlot ), it really depends what your delegate is doing. If you're updating controls you need to update them in the thread on which they were created. This means using Control.InvokeRequired to determine if you need to invoke the method on the thread, then Control.Invoke to actually invoke the method. If you need to set a property create a proxy method to set the value. Through reflection you can also get a MethodInfo for the property's set accessor.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I finally found the problem myself after creating my own unmanaged C++ DLL. This DLL contained the above callback typedef and a stub CAPI_InitMaria() function that simply called the given callback.
The problem was in the DLL's callback method typedef: the MSVC compiler seems to default to a non-"stdcall" calling convention for callback functions. It should have been
typedef int (__stdcall *procCAPI_OnMariaStartup)( const GUID* pInstanceID );
After I changed this in my C++ stub DLL, everything worked like a charm. But of course, I can't do that in the original 3rd party DLL.
I also saw that .NET's PInvoke doesn't seem to support callback functions with a non-stdcall calling convention. So it seems I'm forced to write a second C++ DLL containing a "relay" function and callback for every used function that needs a callback (and yes, there are a LOT! )
Does anyone perhaps know a better workaround for this??? If so, please let me know! It would really save me a HUGE amount of work.
Thanks,
Iwan.
|
|
|
|
|
I am trying to set the grouping / sorting fields at run-time from C#.NET against a Crystal Report.
I'm using the code as provided in the help files using syntax like :
FieldDefinition FieldDef = new FieldDefinition();
FieldDef = Report.Database.Tables[0].Fields["FieldName"];
Report.DataDefinition.Groups[0].ConditionField = FieldDef;
I have the appropriate 'using' set up (for CrystalDecisions.CrystalReports.Engine.FieldDefinition.FieldDefinition()).
When I attempt to compile this code I am presented with a build error suggesting that :
'CrystalDecisions.CrystalReports.Engine.FieldDefinition.FieldDefinition()' is inaccessible due to its protection level'.
I've followed / copied the code sample as suggested within the help files.
Where have I gone wrong / what am I missing ?
Thanks in advance.
|
|
|
|
|
Hi,
Iam getting this error if i compile a project.
error BC31019: Unable to write to output file 'F:\VISTA_EXPRESS\sourcecode\VistaExpressUtil\obj\Debug\VistaExpressUtil.dll': The process cannot access the file because it is being used by another process.
The sln consists of many projects and there are being referenced using Project reference rather than file references, but still the problem.
I tried restarting the system, but still the problem is there.
Any help will be greatly appreciated.
Thanx
saleem
|
|
|
|
|
In one of my solutions (I think it consists of about 25 projects) I also have this problem. Ive even discovered that in this particular case the problem only arises in Release but not in Debug mode. My workaround is to switch the property "Local Copy" (right click the reference and click properties to find it) of the referenced dlls to false. I make this in every project for every Reference where the error occurs. A little problem with this workaround is that sometimes (dont know when it happens exactly) the final output is not 100% up to date. So you should check the output by yourself after doing this.
|
|
|
|
|
Hi Robert,
Iam getting this problem in the debug mode itself.
It's a form application with 20 project references.
Is there any other info u can provide ??
saleem
|
|
|
|
|
I think i got a work around to the problem. Earlier all my binaries output were in the local view of the VOB (Versionised object base). If the output is directed to a folder in the Hard disk ( say, C:\myfolfer\bin), the problem does not occur.
Hope anyone else need not spend time and effort as i did.
Regards,
Saleem
|
|
|
|
|
hi all,
i'm trying to do something seemingly simple, but it's one of the hardest things to google for: Adding a text file into a project (not its path, the file and contents themselves). I'm trying to do this to hardwire in a list of words with my application (about 5000 of them), and would like to avoid having to read them from a text file on the filesystem at runtime.
If you know how to do this, and how to actually read its contents at runtime or even compile time (i know how to use stream readers, but would probably need to know what to give a streamreader constructor), I'd be very grateful for your help. Alternatives are welcome.
If not, thanks for reading this far in an attempt to help...
Z
|
|
|
|
|
You put the file in your project folder, then in Visual Studio right click the project in the Solution Explorer and select Add-->Add Existing Item... then select the file from the file dialog. Select the file in your project in the Solution explorer and press F4 (or right click it and select Properties). In the properties change the Build Action to "Embed Resource" (this will mean that the file will be built into the assembly DLL or EXE file that your project produces)
Next you need to get the file out at run time. For example:
Assembly asm = Assembly.GetExecutingAssembly();
string manifestName = string.Concat(asm.GetName().Name, ".",fileName);
Stream str = asm.GetManifestResourceStream(manifestName);
StreamReader reader = new StreamReader(str);
string scriptSource = reader.ReadToEnd();
You can also find an example that embeds SQL Queries into resources and then runs them against a SQL Server in my blog[^]
Does this help?
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums Upcoming talk:
SELECT UserName, Password FROM Users
-- Getting unauthorised access to a SQL Server, and how to prevent it.
|
|
|
|
|
it certainly does, that's EXACTLY what i was looking for, thanks you very much!
just so i don't have to keep posting and pestering people, is there a resource (no pun intended!) on the web where an example just like this is posted? Would be good to add them to my list of bookmarks...
thanks again
Z
|
|
|
|
|
|
Is there anybody succeed in displaying unicode (especially Thai words) in MsFlexGrid Control?
Thanks in advance for your kind feedback.
|
|
|
|
|
Is there a way to remove the background image from a button, programatically--not manually?
Thanks
|
|
|
|
|
|
button1.BackgroundImage=null;
worked just fine...Thank You.
Paul
|
|
|
|
|
Hi
I have a program. The program functions such that it creates a xml file with data's for any xml schema file(.xsd). It automatically creates data's for each datatypes.
Now I have to input into a single field column with values from another xml file. (for the existence of same field name in the schema) the program should read the schema and check whether any field name is same as that of that input xml file and if exists, then add the values of the input xml into the new xml file .
I have done it as follows
private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
XmlDocument xdc = new XmlDocument();
foreach (DataTable dTbl in dataSet1.Tables)
{
object[] oValues = new object[dTbl.Columns.Count];
xdc.Load(@"C:\CDEV\testdatagenerator\FIELDNAMES.xml");
int i = 0 , iIndex = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
if(dColmn.ColumnName.ToString() == "billto_name" )
{
iIndex = i;
break;
}
i++;
}
xdc.Load(@"C:\CDEV\testdatagenerator\vw_forecast.xml");
XmlNodeList nodeRows = xdc.DocumentElement.SelectNodes("//billto_name");
XmlElement Root = xdc.DocumentElement;
nodeRows = Root.SelectNodes("//billto_name");
for(int j = 0; j <= 200; j++)
{
int k = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
if(k == iIndex && i < nodeRows.Count)
oValues[k] = nodeRows.Item(i).InnerText ;
else
{
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[k] = (string) "castle Hampers" + j;
break;
case "System.Int32":
oValues[k] = (int) 66 + j;
break;
case "System.DateTime":
oValues[k] = new DateTime(2004,01,30).AddDays(j * 1);
break;
case "System.Decimal":
oValues[k] = new Decimal(1900.20) + j;
break;
case "System.Int16":
oValues[k] = (short) 3256 + j;
break;
case "System.Int64":
oValues[k] = (long) 400 + j;
break;
case "System.Double":
oValues[k] = (double) 8888 - j;
break;
case "System.Single":
oValues[k] = (float) 4.5 + j;
break;
}
}
k += 1;
}
i++;
dTbl.Rows.Add(oValues);
}
}
}
I was aked to do as follows
IF the input xml file contains the column name “ADDRESS”
Open the new input file ADDRESS.xml which is just a text file
(there is no schema in this file) containing about 50 valid values of ADDRESS and put them in the output file in the right column.
To make the process more generic what you should do is:
CREATE A NEW XML FILE CALLED SAY, FIELDNAMES.XML
This file is again just a text file containing just the actual field
names. There is no schema for this file. For the time being let it just
contain 1 line of text which says ADDRESS
So first loop through the schema in your input file (i.e the input file
you have entered on screen)
If any field name from the schema exists in the file FIELDNAMES.XML,
store the position of this field name and the fieldname in an array.
So if in your input file ADDRESS field is the 4th field, this array
will contain (4 , ADDRESS)
Then when you are looping through in your program to build the 200
records, Compare the field number to the field number in the array and when they
are equal update it correctly.
SOME HELP FOR THAT WITH CODINGS.
PLS HELP ME TO DO THIS
as the "Load" button is clicked. It is a kind of pseudo code.
xdc.Load(@"C:\CDEV\generator\testdatagenerator\FIELDNAMES.xml");
Read through this file and create an ArrayList
ArrayList fieldnameslist = new ArrayList();
fieldnameslist.Add(text from FIELDNAMES.xml)
Here you must include code to build an ArrayList from the file FIELDNAMES.xml
See code below. You are expected to put the code properly.
Create a separate class which looks as follows:
public class DataCol
{
public int ColIndex;
public string ColDesc;
public DataCol()
{
}
public DataCol(int colindex, string coldesc)
{
this.ColIndex = colindex;
this.ColDesc = coldesc;
}
}
Instantiate an ArrayList
ArrayList mylist = new ArrayList();
foreach (DataTable dTbl in dataSet1.Tables)
{
int i = 0 , iIndex = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
for (int y = 0 to y <= (fieldnameslist.count-1))
{
if(dColmn.ColumnName.ToString() == fieldnameslist[y])
{
iIndex = i;
mylist.Add(new DataCol(ilindex, fieldnameslist[y]));
HERE YOU CAN CREATE THE FILENAME TOO FROM FIELDNAMESLIST[Y] AND OPEN IT - FOR EXAMPLE ADDRESS..xml
break;
}
}
i++;
}
}
All you have done in the above code is create an array list with the column number and column desc.
So say the file FIELDNAMES.xml has the text billto_name and the text shipto_name
Then if in the input file that I have entered on screen has billto_name as the 5th column and shipto_name as the 7th column in it's schema then,
ArrayList myList[0] colindex will be = 5
myList[0] coldesc will be = "billto_name"
myList[1] colindex will be = 7
myList[1] coldesc will be = "shipto_name"
After this you will have to loop through your DataTable dTbl again and compare the ColumnName to ColDesc in the ArrayList mylist while building the records.
please help me to do this. I need some coidng help. Help me to finish it in full way.
ramya
|
|
|
|
|
I would like to pull out some icons from
Windows (Its Shell32 Dll)to Image list
How can i approach to those icons ??
C# Windows Form
|
|
|
|
|
How can read a text by text to speech microsft engine ?
Regards' AmirJalaly
|
|
|
|
|