|
I thought that the variable you pointed to had to be fixed, but not the pointer. I think you need to declare buff as,
fixed byte[] buff = new byte[20]; If that doesn't work, then perhaps you should try the following:
IntPtr bytePtr = Marshal.AllocHGlobal(20);
try {
ret = foo((byte*)bytePtr.ToPointer(), 20);
} finally {
Marshal.FreeHGlobal(bytePtr);
} Or perhaps the argument to your method foo is supposed to be 19 in this case instead of 20. Hope one of these suggestions helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
protected override void OnMouseUp(MouseEventArgs e)
{
int WM_CONTEXTMENU = 0x7B;
this.Capture = false;
Message msg = Message.Create(this.Handle, WM_CONTEXTMENU, ???, ???);
DefWndProc(ref msg);
}
=========================================
Dear Sir And Madam,
The code above....
I need to show Windows Form Title Bar Context Menu.
Message msg = Message.Create(this.Handle, WM_CONTEXTMENU, ???, ???);
What parameter I should create and pass to Message.Create method.
Sorry for bad English.
Thank You.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DateSelectionforPGE
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
selectDate();
connectSQl();
}
public void connectSQl()
{
SqlConnection conObj = new SqlConnection("Server=localhost;Integrated security=SSPI;database=master");
conObj.Open();
}
public void selectDate()
{
//To take the Database Name
string nameDatabase = dateTimePicker1.Value.ToString("MMdd");
string nameDB = "CustList_PGE_" + nameDatabase;
MessageBox.Show("The name of the database will be CustList_PGE_" + nameDatabase);
//To take the Database Table
string nameDatabasetable = dateTimePicker1.Value.ToString("MMddyy");
string nameTable = "CustList_PGE" + nameDatabasetable;
MessageBox.Show("The name of the Database table will be CustList_PGE" + nameDatabasetable);
//Connecting to the Stored Procedure
SqlCommand cmdObj = new SqlCommand();
cmdObj.CommandText = "CreateDataBases";
cmdObj.CommandType = CommandType.StoredProcedure;
cmdObj.Parameters.AddWithValue("@databaseName", nameDB);
cmdObj.ExecuteNonQuery();
}
}
}
|
|
|
|
|
I have a config class that is decorated using attributes from System.Xml.Serialization, so reading of the configuration files is easy. There are dozens of instances of those configuration files, which are loaded on demand specifying the file name to indicate which instance we want.
I want to change this in the following way: instead of the clients of the class instantiating a new instance of XmlSerializer each time, specifying the file name, I want to encapsulate it as a static member instance, created on class initialization. Then, I want to provide a static method, member of the config class, that will take a file name and return the appropriate instance.
Now that you have the context, here is the question: since the XmlSerializer is a static member and more than one thread can call the static method to get an instance at the same time, is the XmlSerializer.Deserialize method thread-safe?
Thank you.
|
|
|
|
|
Hello,
I'm also not sure about this one.
Out of a feeling I would asume it is not.
Therfore I would implement a static Deserialize method ans use a lock[^] statement there.
All the best,
Martin
|
|
|
|
|
There are a few issues with what you posted
Le Centriste wrote: since the XmlSerializer is a static member and more than one thread can call the static method
Double static? What is the point of having a static instance of the XmlSerializer if you have a static method that will be used?
Le Centriste wrote: I want to provide a static method, member of the config class, that will take a file name and return the appropriate instance.
Based on that information alone, since a static method returns a new instance based on the specific input on each invocation there is no concurrency issue requiring synchronization. However I have no idea what else you may be doing.
led mike
|
|
|
|
|
Ok, I should have posted some code:
public MyConfigClass
{
private static XmlSerializer DEF_SERIALIZER = new XmlSerializer(typeof(MyConfigClass));
[XmlElement]
public string SomeConfigValue
{
get { return this._correspondingPrivateMember; }
set { this._correspondingPrivateMember = value; }
}
public static MyConfigClass LoadConfig(Stream file)
{
return (MyConfigClass)MyConfigClass.DEF_SERIALIZER.Deserialize(file);
}
public void SaveConfig(Stream file)
{
MyConfigClass.DEF_SERIALIZER.Serialize(file, this);
}
}
Note that I provide overloads of those methods to accomodate the clients, but you get the idea.
So, since the MyMyConfigClass.LoadConfig method is static, it may be called simultaneously by different threads, on different streams, but all using the same XmlSerializer instance.
|
|
|
|
|
Well I could have figured out your construct from your post but I didn't.
You actually have two things you need to worry about. The instance of XmlSerializer and the Stream.
A rule of thumb is that static methods should be thread safe where instance methods cannot be assumed to be thread safe. Your static method is not since it uses an instance member to perform it's work. You could synchronize access or create a new Serializer instance in the static method. However neither guarantees thread safty of the Stream.
led mike
|
|
|
|
|
led mike wrote: Your static method is not since it uses an instance member to perform it's work
If you talk about the XmlSerializer, it is static, hence is not an instance member.
led mike wrote: You could synchronize access
I think it would be safer that way. A simple lock statement would guarantee thread-safety. This was also suggested by Martin#.
led mike wrote: However neither guarantees thread safty of the Stream.
Good catch. I cannot guarantee that, since 2 thread could pass the same Stream instance.
I need to put in some more thinking. Thanks for your help.
|
|
|
|
|
Le Centriste wrote: If you talk about the XmlSerializer, it is static, hence is not an instance member.
Yes it is, it's a Singleton.[^]
led mike
|
|
|
|
|
This is not a singleton it is just Encapsulation or Information Hiding[^]. There could exist other instances of XmlSerializer, but MyConfigClass uses a predefined one, and avoids creating useless instances. In the singleton pattern, only one instance of a given class can exist at any given time.
Also, the MyConfigClass class does not prevent mulitple instances to exist at the same time.
|
|
|
|
|
You are correct, you did not implement a Singleton. However it is an instance so your assertion that it isn't is still wrong.
led mike
|
|
|
|
|
From your link:
the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object
I don't, in any way, restrict the instantiation of XmlSerializer or MyConfigClass to one object. Other part of the application can instantiate other instances of XmlSerializer. In a Singleton pattern, this is not possible. I just hide the XmlSerializer instance I use to deserialize the object.
Anyway, I just wanted to know if the XmlSerializer.(De)Serialize methods were thread-safe.
|
|
|
|
|
hi everybody,
i can't change the axe X in excel with C# i know with vb serialcollection.XValue= but i need the information for c#
thanks
<br />
public void Excel_Graphic(int Lig, int col)<br />
{<br />
string upperLeftCell = "A3";<br />
int endRowNumber = System.Int32.Parse(upperLeftCell.Substring(1))<br />
+ Lig - 1;<br />
char endColumnLetter = System.Convert.ToChar(<br />
Convert.ToInt32(upperLeftCell[0]) + col - 1);<br />
string upperRightCell = System.String.Format("{0}{1}",<br />
endColumnLetter, System.Int32.Parse(upperLeftCell.Substring(1)));<br />
string lowerRightCell = System.String.Format("{0}{1}",<br />
endColumnLetter, endRowNumber);<br />
<br />
Worksheet ws = (Worksheet)app.ActiveSheet;<br />
<br />
Object Graph1 = new Object(); <br />
<br />
ChartObjects GraphObjs = (ChartObjects)ws.ChartObjects(Type.Missing);<br />
ChartObject GraphtObj = GraphObjs.Add(100, 20, 300, 300);<br />
<br />
Chart xlChart = GraphtObj.Chart;<br />
<br />
Range chartRange = ws.get_Range("A2", lowerRightCell);<br />
Range AxeY = ws.get_Range("A2", "A16");<br />
Range AxeX = ws.get_Range("B2", "B16");<br />
<br />
xlChart.SetSourceData(AxeY, Type.Missing);<br />
xlChart.ChartType = XlChartType.xlXYScatterLines;<br />
xlChart.Location(XlChartLocation.xlLocationAsNewSheet, Graph1);<br />
<br />
}</code> <br />
<br />
<div class="ForumSig">jere</div>
|
|
|
|
|
Hello,
I realized nobody answered this, and even if its been so long I will try to give an answer.
To change the X values, you need to get the series, and set the series X values to your "AxeX". Like this:
xlChart.SetSourceData(AxeY, Type.Missing);
Excel.Series series = (Excel.Series)xlChart.SeriesCollection(1);
series.XValues = AxeX;
|
|
|
|
|
I want to write a function to change the color property of all the controllers from an XML. XML tags are same as the controller names.
public void LoadProperties(Control control)
{
string name = control.Name;
control.ForeColor = ColorTranslator.FromHtml(xDoc1.SelectSingleNode("COLOR/Settings/" + (Name + "/ForeColor").InnerText.Trim());
}
So if the name exist in the XML it will retrieve the color info of fore and back color and and overwrite with the default ones.
XML:
<color> <settings>
<label1>
<forecolor>#FFFFFF
<backcolor>#330000
therefore under InitializeComponent(); when I run :
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
// LoadProperties(this.label1);
LoadProperties will overwrite the default ForeColor with #FFFFFF
Right now it doesnt work. Do I have a logical mistake?
Thanks
|
|
|
|
|
cant copy/paste the xml here for some reason but its like:
-COLOR-
-Settings-
<label1>
<forecolor>#FFFFFF
<backcolor>#330000
-/COLOR-
-/Settings-
|
|
|
|
|
s3rro wrote: for some reason
Not for "some" reason. The reason is, you have NOT READ the CodeProject Posting guidelines and instruction which explain how to post messages containing less than and greater than symbols. NOT READING is likely also the reason you can't solve your own software development problem.
led mike
|
|
|
|
|
Hi there,
I will try to explained my problem.
I have an old lab balance attached to a PC via rs232 com port1 and need to interrogate the balance for data when an item has been weighted.
The balance does not send data to the PC input buffer I need to go get the info from its buffer.
The SerialPort class in C# does allow read/write to the PC buffer and that I know how to do but I do I question the balance for data that i don't.
The annoying thing is that I have a very old QBasic application that does the trick fine but I am unable to do it in C#.
Thanks
|
|
|
|
|
If you have the qbasic code then you can translate that. If not, you'll have to use a serial port sniffer to see what values are transmitted and received between the port and hardware so you can code these into your app.
Dave
|
|
|
|
|
Thanks Dave.
The QBasic lines are as follow
349 Open "COM1:1200,O,7,1,ASC,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" For Random As 2
350 Print #2, Chr$(27); "P"
The user needs to press return at line 348 then the balance value is displayed on the console.
I suppose "For Random As 2" does the job but I can't see how it would translate to C#.
I will investigate the port sniffer you mentioned.
Scalpa
|
|
|
|
|
Hi,
the code you have shown is not complete.
line 349 simply opens the serial port, and sets a lot of settings, but it does not
do any actual input/output; AFAIK RANDOM does not make for serial ports, and the
"As 2" simply means input and output statements will use a #2 to refer to it.
line 350 sends an escape (ESC) character and a letter P to the device (probably
followed by a CR/LF)
the actual input and display code must follow that. the command looks like ASCII,
so chances are the return data is a text string too, making things rather easy.
You will need some investigative work here:
- first find out what all the options in line 349 amount to, and find the equivalent
in the SerialPort class; I guess (please check all!) 1200 Baud, no parity, 7 data bits,
1 stop bit, ASCII, and the polarity of a lot of control lines;
I also guess TB and RB set buffer sizes and don't really matter.
- I don't think a sniffer would really help here, it too would require all the correct
settings
- now you could try to use a terminal emulator (such as HyperTerminal, part of Windows);
when all parms are set correctly, you could simply type ESC P (and possibly ENTER)
and read what got returned. Once this works, start coding with SerialPort.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hey thanks a lot for your interest.
Here is the complete QBasics
10 Rem field bean program to recieve weights from sartorius balance
60 INPUT "DO YOU WANT HELP (Y/N)", H$
70 If H$ = "Y" Then GoTo 480
80 H$ = "N"
90 Close All
120 Print "ENTER PLOT NUMBER AS A 3 DIIGIT NUMBER 001"
121 Close #1
130 INPUT "PLOT NO ", B$
131 B$ = B$ + ".DER"
133 On Error GoTo 139
134 OPEN "I", 1, B$
136 Print "THIS PLOT HAS ALREADY BEEN MEASURED"
137 PLAY "AABBCC"
138 GoTo 120
139 Rem CLOSE #1
140 OPEN "O", 1, B$
150 Rem INPUT "ENTER NO OF VARIETIES ", V
160 C = 0
170 Rem IF C = V THEN CLOSE ALL: GOTO 880
180 C = C + 1
190 Rem FOR J = 1 TO 4
200 P = 0
210 PLAY "F"
220 Rem PRINT "VARIETY "; C: PRINT "REP "; J
230 Rem PRINT "ENTER PLOT HEADING IN FOLLOWING FORMAT"
240 Rem INPUT " PLOT NO'372' ?", PH$
250 Rem INPUT "AFPNO ?", AFP$
260 Rem PLAY "A"
280 Rem PRINT #1, PH$
285 Rem PRINT #1, AFP$
286 Let ch2$ = "1 20": Print #1, ch2$
290 Let ch$ = "29"
295 Let ch1$ = "SEEDWT"
296 Let ct$ = ch$ + ch1$
297 Print #1, ct$
300 If P = 20 Then GoTo 440
305 TIMEOUT = 10000
310 Rem Balance routine****************************
315 Print P + 1
320 INPUT "PUT SEED ON SCALES PRESS RETURN THEN TARE SCALES TO ZERO", CR$
330 P = P + 1
340 Open "COM1:1200,O,7,1,ASC,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" For Random As 2
350 Print #2, Chr$(27); "P"
360 Line Input #2, W$
370 W = Val(W$): Rem W = real format of weight:REM W$ = String format of weight
380 Close #2
390 Rem End of balance routine*********************
400 Print W
410 W1$ = Mid$(W$, 7, 4)
411 If W1$ <> "0.00" Then GoTo 420
412 W1$ = "-1"
420 Print #1, W1$
430 GoTo 300
440 P = 0
450 Rem NEXT J
451 PLAY "EAG"
453 INPUT " ANOTHER PLOT Y/N ", A$
454 If A$ = "N" Then GoTo 471
460 Print "NEXT VARIETY": PLAY "B"
465 Close #1
470 RUN 90
471 Close #1
472 Cls
473 End
480 Rem HELP
490 Print " HELP FILE"
500 Print " ---- ----"
510 Print "IN ORDER FOR BALANCE.BAS TO WORK AND THE CABLE FROM BALANCE TO COMPUTER MUST BE CONNECTED PROPERLY SEE DIAG"
520 INPUT "PRESS RETURN TO CONTINUE", RT$
530 Cls
540 Print " "; " "; "-----------------"
550 Print " "; " "; "! !"
560 Print "___________________"; " "; "! !"
570 Print "! BALANCE !"; " "; "! COMPUTER !"
580 Print "! (BACK) !"; " "; "! (BACK) !"
590 Print "! !"; " "; "! !"
600 Print "! !"; " "; "! !"
610 Print "!_________________!"; " "; "!_______________!"
620 Print " __________"; " "; "___________________________________"
630 Print " ! !PLUG! !"; " "; "! !"
640 Print " ! !PORT! !"; " "; "! !!MOUSE!! !"
650 Print " !--------!"; " "; "! !"
660 Print " ^ "; " "; "! !!BALANCE!! !"
670 Print " ^ "; " "; "!--------- ^ ---------------------!"
680 Print " ^============================^"
690 INPUT "PRESS RETURN TO CONTINUE", RT$
700 Print: Print
740 Print " TO LOAD THE BALANCE PROGRAM YOU MUST BE IN C: DRIVE THEN SIMPLE TYPE": Print " 'GWBASIC BALANCE' FOLLOWED BY RETURN"
750 Print "THE PROGRAM THEN ASKS IF YOU NEED HELP TYPE 'Y' OR 'N' THEN RETURN"
760 Print "THE PROGRAM THEN ASKS FOR A FILENAME IN THE FORMAT C:\WS\FABA\filename"
770 Print "eg C:\WS\FABA\TEST.DAT"
780 Print "THE PROGRAM THEN ASKS FOR THE NUMBER OF VARIETIES"
790 Print "THE PROGRAM THEN ASKS FOR THE PLOT NUMBER IN THE CORRECT FORMAT"
800 Print "THE PROGRAM WILL BEEB IF THIS IS ENTERED INCORRECTLY."
810 Print "YOU ARE NOW READY TO WEIGH A SAMPLE OF SEED."
820 Print "SIMPLE PUT ONE SEED ON SCALES THEN PRESS RETURN WHEN HAPPY WITH WEIGHT"
830 Print "THEN TARE SCALES TO ZERO AND PUT NEXT SEED ON."
840 Print "CONTINUE FOR 20 SEEDS WHEN THE COMPUTER WILL BEEP YOU FOR NEXT REP OF VARIETY"
850 INPUT "PRESS RETURN TO CONTINUE", CR$
860 Cls
870 GoTo 80
880 PLAY "FACE": INPUT "DO YOU WANT ANOTHER RUN (Y/N) ?", R$
890 If R$ = "Y" Then GoTo 10
900 If R$ = "" Then GoTo 880
910 R$ = "N": Stop
as for Hyperterm I am unable to enter any commend in it when the balance is connected to my PC
Thanks for your help.
Scalpa
|
|
|
|
|
Scalpa wrote: 360 Line Input #2, W$
370 W = Val(W$): Rem W = real format of weight:REM W$ = String format of weight
Nice. Line 360 just reads a string, so the device outputs text, which you can look at
with HyperTerminal.
And Line 370 turns the text into a number, in C# that would be something like
int.TryParse() or float.TryParse().
As I said before, it's time to google and experiment about the control lines;
your PC probably must set some lines high/low otherwise the device may not respond.
Alternatively, you could just give it a try, open HyperTerminal, open a connection
at 1200 baud, and type ESC P ENTER, just to see what if anything comes in...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc, I really do appreciate your time an effort.
I have been on this for 2 days, hours on googles etc...
The thing is we also have a MFC application that works (not the source code though) fine but I need to do it in the .net framework for loading onto handheld devices.
I will investigate further and post the answer if even, when ever I find it.
Thanks again.
|
|
|
|
|