|
I do not think this is likely to be a C# issue.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
This may sound like a "blow you off" response, but I assure you that's not my intent: you are proposing the equivalent of blood transfusions between different species.
The answer, I think you'll find, will be found in implementing client-side UI using jQuery, and/or other libraries that extend JavaScript.
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Make sure you use a menu control or partial view that is coded correctly. Unfortunately various parts of the non-MVC Microsoft control library isn't and it doesn't provide a good user experience (including some browser problems like this), and many third party controls are dubious, though if you have the source at least you can fix those.
Alternatively, write a menu control yourself, it's not that hard (I've done it in PHP before).
|
|
|
|
|
hello,
i am working on a USB HID device. it's a proximity device which detects the person's distance and fire keystrokes accordingly. i want the handle for the device so that i can perform the read and write operations over it.
i am using Hid.dll , Setupapi.dll , kernel32.dll. when i am using the CreateFile function, it is reaturning the invalid handle. can anybody help me in this regard.
the code is written below:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1() : base()
{
InitializeComponent();
}
[ StructLayout( LayoutKind.Sequential ) ]
internal class DEV_BROADCAST_HDR
{
internal Int32 dbch_size;
internal Int32 dbch_devicetype;
internal Int32 dbch_reserved;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class DEV_BROADCAST_DEVICEINTERFACE_1
{
internal Int32 dbcc_size;
internal Int32 dbcc_devicetype;
internal Int32 dbcc_reserved;
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.U1,
SizeConst = 16)]
internal Byte[] dbcc_classguid;
[MarshalAs(UnmanagedType.ByValArray,
SizeConst = 255)]
internal Char[] dbcc_name;
}
[DllImport("hid.dll", SetLastError = true)]
public static extern void HidD_GetHidGuid(ref System.Guid HidGuid);
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern IntPtr SetupDiGetClassDevs
(ref System.Guid ClassGuid,
IntPtr Enumerator,
IntPtr hwndParent,
Int32 Flags);
public struct SP_DEVINFO_DATA
{
public int cbSize;
public System.Guid ClassGuid;
public int DevInst;
public int Reserved;
}
internal struct SP_DEVICE_INTERFACE_DATA
{
internal Int32 cbSize;
internal Guid InterfaceClassGuid;
internal Int32 Flags;
internal IntPtr Reserved;
}
[DllImport("setupapi.dll", SetLastError = true)]
internal static extern Boolean SetupDiEnumDeviceInterfaces
(IntPtr DeviceInfoSet,
IntPtr DeviceInfoData,
ref System.Guid InterfaceClassGuid,
Int32 MemberIndex,
ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
internal struct SP_DEVICE_INTERFACE_DETAIL_DATA
{
internal Int32 cbSize;
internal String DevicePath;
}
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern Boolean SetupDiGetDeviceInterfaceDetail
(IntPtr DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
IntPtr DeviceInterfaceDetailData,
Int32 DeviceInterfaceDetailDataSize,
ref Int32 RequiredSize,
IntPtr DeviceInfoData);
[DllImport("setupapi.dll", SetLastError = true)]
internal static extern Int32 SetupDiDestroyDeviceInfoList
(IntPtr DeviceInfoSet);
[DllImport("setupapi.dll", SetLastError = true)]
internal static extern Boolean SetupDiEnumDeviceInfo(
IntPtr DeviceInfoSet,
Int32 MemberIndex,
SP_DEVINFO_DATA DeviceInfoData);
internal const Int32 DBT_DEVTYP_HANDLE = 6;
internal const Int32 DBT_DEVTYP_DEVICEINTERFACE = 5;
internal const Int32 DEVICE_NOTIFY_WINDOW_HANDLE = 0;
internal const Int32 DIGCF_PRESENT = 2;
internal const Int32 DIGCF_DEVICEINTERFACE = 0X10;
internal const Int32 WM_DEVICECHANGE = 0X219;
[StructLayout(LayoutKind.Sequential)]
internal class DEV_BROADCAST_DEVICEINTERFACE
{
internal Int32 dbcc_size;
internal Int32 dbcc_devicetype;
internal Int32 dbcc_reserved;
internal Guid dbcc_classguid;
internal Int16 dbcc_name;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern IntPtr RegisterDeviceNotification
(IntPtr hRecipient,
IntPtr NotificationFilter,
Int32 Flags);
internal const Int32 DBT_DEVICEARRIVAL = 0X8000;
internal const Int32 DBT_DEVICEREMOVECOMPLETE = 0X8004;
public static Guid
GUID_DEVINTERFACE_USB_DEVICE = new Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED");
internal const Int32 FILE_ATTRIBUTE_NORMAL = 0X80;
internal const Int32 FILE_FLAG_OVERLAPPED = 0x40000000;
internal const Int32 FILE_SHARE_READ = 1;
internal const Int32 FILE_SHARE_WRITE = 2;
internal const UInt32 GENERIC_READ = 0X80000000;
internal const UInt32 GENERIC_WRITE = 0X40000000;
internal const Int32 OPEN_EXISTING = 3;
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern SafeFileHandle CreateFile
(String lpFileName,
UInt32 dwDesiredAccess,
Int32 dwShareMode,
IntPtr lpSecurityAttributes,
Int32 dwCreationDisposition,
Int32 dwFlagsAndAttributes,
Int32 hTemplateFile);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern int GetLastError();
[StructLayout(LayoutKind.Sequential)]
internal struct HIDD_ATTRIBUTES
{
internal Int32 Size;
internal UInt16 VendorID;
internal UInt16 ProductID;
internal UInt16 VersionNumber;
}
[DllImport("hid.dll", SetLastError = true)]
internal static extern Boolean HidD_GetAttributes
(SafeFileHandle HidDeviceObject, ref HIDD_ATTRIBUTES Attributes);
internal SafeFileHandle deviceHandle;
private Boolean Find(Message m)
{
Boolean deviceFound ;
Int32 bufferSize = 0;
IntPtr detailDataBuffer;
String[] devicePathName = new String[128];
Int32 memberIndex = 0;
ntPtr deviceInfoSet ;
deviceInfoSet = SetupDiGetClassDevs
(ref GUID_DEVINTERFACE_USB_DEVICE,
IntPtr.Zero,
IntPtr.Zero,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
deviceFound = false;
SP_DEVICE_INTERFACE_DATA MyDeviceInterfaceData = new SP_DEVICE_INTERFACE_DATA();
Boolean success = false;
MyDeviceInterfaceData.cbSize = Marshal.SizeOf( MyDeviceInterfaceData );
success = SetupDiEnumDeviceInterfaces
(deviceInfoSet,
IntPtr.Zero,
ref GUID_DEVINTERFACE_USB_DEVICE,
memberIndex,
ref MyDeviceInterfaceData);
if (!success)
{
return false;
}
else
{
success = SetupDiGetDeviceInterfaceDetail
(deviceInfoSet,
ref MyDeviceInterfaceData,
IntPtr.Zero,
0,
ref bufferSize,
IntPtr.Zero);
detailDataBuffer = Marshal.AllocHGlobal(bufferSize);
Marshal.WriteInt32
(detailDataBuffer, (IntPtr.Size == 4) ? (4 + Marshal.SystemDefaultCharSize) : 8);
success = SetupDiGetDeviceInterfaceDetail
(deviceInfoSet,
ref MyDeviceInterfaceData,
detailDataBuffer,
bufferSize,
ref bufferSize,
IntPtr.Zero);
IntPtr pDevicePathName = new IntPtr(detailDataBuffer.ToInt32() + 4);
devicePathName[memberIndex] = Marshal.PtrToStringAuto(pDevicePathName);
MessageBox.Show("path of device " + devicePathName[memberIndex]);
DEV_BROADCAST_DEVICEINTERFACE_1 devBroadcastDeviceInterface =
new DEV_BROADCAST_DEVICEINTERFACE_1();
DEV_BROADCAST_HDR devBroadcastHeader = new DEV_BROADCAST_HDR();
Marshal.PtrToStructure(m.LParam, devBroadcastHeader);
if ((devBroadcastHeader.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE))
{
Int32 stringSize = Convert.ToInt32((devBroadcastHeader.dbch_size - 32) / 2);
Array.Resize(ref devBroadcastDeviceInterface.dbcc_name, stringSize);
Marshal.PtrToStructure(m.LParam, devBroadcastDeviceInterface);
String deviceNameString = new String(devBroadcastDeviceInterface.dbcc_name, 0, stringSize);
MessageBox.Show("extracted path-: " + deviceNameString.ToString());
if ((String.Compare(deviceNameString, devicePathName[0], true) == 0))
{
MessageBox.Show("device name matched");
}
else
{
MessageBox.Show("device name not matched");
}
}
deviceFound = true ;
}
if (deviceFound)
{
MessageBox.Show(devicePathName[0]);
MessageBox.Show("inside file handle");
deviceHandle = CreateFile
("##?#USB#Vid_18c8&Pid_2bfa#063#{A5DCBF10-6530-11D2-901F-00C04FB951ED}",0, FILE_SHARE_READ | FILE_SHARE_WRITE,
IntPtr.Zero, OPEN_EXISTING, 0, 0);
MessageBox.Show("file handle " + deviceHandle.ToString());
MessageBox.Show("handle value : " + deviceHandle.DangerousGetHandle().ToString());
if (!deviceHandle.IsInvalid)
{
MessageBox.Show("valid");
HIDD_ATTRIBUTES attribs = new HIDD_ATTRIBUTES();
attribs.Size = Marshal.SizeOf(attribs);
HidD_GetAttributes(deviceHandle, ref attribs);
MessageBox.Show("vendor id " + Convert.ToString(attribs.VendorID, 16));
}
else
{
int error = GetLastError();
MessageBox.Show("in else " + error.ToString());
}
}
return deviceFound;
}
private void Register()
{
DEV_BROADCAST_DEVICEINTERFACE devBroadcastDeviceInterface =
new DEV_BROADCAST_DEVICEINTERFACE();
IntPtr devBroadcastDeviceInterfaceBuffer;
IntPtr deviceNotificationHandle = IntPtr.Zero;
Int32 size = 0;
size = Marshal.SizeOf( devBroadcastDeviceInterface );
devBroadcastDeviceInterface.dbcc_size = size;
devBroadcastDeviceInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
devBroadcastDeviceInterface.dbcc_reserved = 0;
devBroadcastDeviceInterface.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
devBroadcastDeviceInterfaceBuffer = Marshal.AllocHGlobal( size );
Marshal.StructureToPtr
( devBroadcastDeviceInterface,
devBroadcastDeviceInterfaceBuffer,
true );
deviceNotificationHandle = RegisterDeviceNotification
(new Form1().Handle,
devBroadcastDeviceInterfaceBuffer,
DEVICE_NOTIFY_WINDOW_HANDLE);
}
private void Form1_Load(object sender, EventArgs e)
{
Register();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_DEVICECHANGE)
{
OnDeviceChange(m);
}
base.WndProc(ref m);
}
private void OnDeviceChange(Message m)
{
if ((m.WParam.ToInt32() == DBT_DEVICEARRIVAL))
{
MessageBox.Show("device arrived");
if (Find(m))
{
MessageBox.Show("my device arrived");
}
}
else if ((m.WParam.ToInt32() == DBT_DEVICEREMOVECOMPLETE))
{
MessageBox.Show("device removed");
}
}
}
}
|
|
|
|
|
What is the value returned from GetLastError() ?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
value returned by GetlastError() is 0.
|
|
|
|
|
I think you need to capture it immediately after the call to CreateFile() , i.e. before the two MessageBox.Show() calls. I also think you have some strange characters in your device path: # instead of \ .
BTW it would be much easier to help with this if you had posted just the code that was failing.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
value of GetLastError() is coming 31 if a catch it just after CreateFile().
if i remove the # by \, still i am facing the same problem. so no problem in the path.
|
|
|
|
|
anuj_jain wrote: if i remove the # by \, still i am facing the same problem. so no problem in the path.
I don't think that's correct. A Windows device path always starts with a backslash, and if you put that in a C# string then you need to use the @ prefix, or use double backslash to ensure the resulting path is correct. You should also check to see what error code 31 means.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
ok. i get your point. i check it by removing # with /. i am facing the same problem.
error 31 means--- "A device attached to the system is not functioning."
but device is working properly. how come application is no detecting it correctly???
is my other part of code working fine??? can you please help me in that????
|
|
|
|
|
anuj_jain wrote: i check it by removing # with /.
You really need to a) read my suggestions more closely and b) read up on the format of Windows file and device paths, and C# string constants. Your path should be one of the following:
deviceHandle = CreateFile
("\\\\?\\USB\\Vid_18c8&Pid_2bfa\\063\\{A5DCBF10-6530-11D2-901F-00C04FB951ED}",0, FILE_SHARE_READ |
deviceHandle = CreateFile
(@"\\?\USB\Vid_18c8&Pid_2bfa\063\{A5DCBF10-6530-11D2-901F-00C04FB951ED}",0, FILE_SHARE_READ |
As to reading the rest of your code, I do not have the time or experience to be able to judge it. It is up to you to do your own testing and debugging, a vital part of a developer's job.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
anuj_jain wrote: error 31 means--- "A device attached to the system is not functioning." but
device is working properly. how come application is no detecting it
correctly???
Just because it says that a device is not functioning correctly doesn't mean that it's the device YOU are thinking about. Your code is trying to get at a device using a string that describes something other than what you're thinking. In other words, the device your badly formatted string is pointing at doesn't exist, so yeah, it's not functioning.
|
|
|
|
|
it's my bad that i posted the whole code. i am facing the problem in CreateFile() function.
the code is written below. Moreover, i changed the path and put it into the array variable. so now i think that it is more readable.
The code is as follows:-
deviceHandle = CreateFile(devicePathName[0], GENERIC_WRITE | GENERIC_READ, 0, IntPtr.Zero,
OPEN_EXISTING, 0, IntPtr.Zero);
|
|
|
|
|
i posted the whole code so that one can have a look at whole code. if i am going wrong anywhere, one can point me.
CreateFile() function is failing. i am not able to get the handle to the device for read and write function.
is my other part of the code is fine or i need to change somewhere else also??
|
|
|
|
|
You need to be more specific about the problem. It's not reasonable to expect people to go through your entire test application and debug it for you. If CreateFile is failing it is because you are passing the wrong things to it – I agree with the answer above that says that that path doesn't look correct, and you probably need to look again at how to correctly request a handle to a USB device.
|
|
|
|
|
i had changed the path as told by RICHARD. still i am facing the same problem.
i am facing the problem in CREATEFILE() function.
|
|
|
|
|
Hi All
Iam facing issue while reading the document when runnning code from IIS. It is not reading the document and throwirng an error "No document is opne when trying to save the activedocument.".
m_word.Documents.Open(ref FileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
m_word.ActiveDocument.SaveAs2(ref FileName_rtf, ref FileFormat, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1);
m_word.ActiveDocument is giving error when running from IIS. It is working in visual studio debugging mode.
I also tried the below code. Document doc_open = m_word.Documents.Open(ref FileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); doc_open.Activate();
doc_open is retruning null and it throws object reference error in the second line. this works when code is in debugging mode. Error occurs when ran from IIS on development server where we have IIS 7 and MS offices too.
Please help on this IAm struggling from 5 days.
Thanks in advance
|
|
|
|
|
Hi,
Try making the visible property to true while opening the document , or make the opened document active before saving it.
Like,
doc1.Activate();
|
|
|
|
|
hello guys... I have this datagridview in which I show students. Now when I add more than one students in this grid and update their data, it shows me this error
<pre>Object Can not be Bast From DBNullto Other Types</pre>
Here is the code I am using to loop through and update these students from gridview
<pre lang="c#">
foreach (DataGridViewRow row in dgStudents.Rows)
{
object obj = row.Cells["colStudentId"].Value;
if (obj != null)
{
StudentID = Convert.ToInt32(row.Cells["colStudentId"].Value);
Fee = Convert.ToInt32(row.Cells["colFee"].Value);
NumOfSubject = Convert.ToInt32(row.Cells["colNumOfSubject"].Value);
}
}
</pre>
Even though I check for null values taken from gridview, it still shows me this error. Whats wrong? thnx
-- modified 4-Jan-12 1:04am.
|
|
|
|
|
try this:
if(row.Cells["colStudentId"].Value != DBNull.Value){
...
}
hope this helps.
V.
|
|
|
|
|
Thnx for your time. Actually I had to check all numeric types against null, in the grid.
Then it did not happen again.
|
|
|
|
|
Plus, Int32.Parse and Int32.TryParse are preferable to Convert.ToInt32 -- dont use Convert.
|
|
|
|
|
how to call the database to be displayed,,
through programming asp.net with c#,,
because of problems that came out at compile time
myLayer.DataSource = new SharpMap.Data.Providers.katmai (ConnStr, "dbo.sysdiagrams", "dbo.Geocode", "OidColumn");
please give an example at all,,,
thank you
modified 2-Jan-12 21:08pm.
|
|
|
|
|
I'm sure English is not your native language, but it is the default language for this site.
In English, your question makes no sense at all.
Please, either try to find a better translation of your question to English, or find a site in your own native language, as they may be able to help you better than we can!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
hello friends I work for several months in my hand Makel bi business counters and Kohler have not comport with the remote trying to read them in c # la. and the cable will be connected to a one count. I would say that bi does not like to read one of a few sayacdan. but please do not get the help you lead a more bi olurmusunuz How do I make this work. I give all the settings of the timer in visual studio, how will I am using the SerialPort object. I need to send data to send data to the meter data to come to the counter where the error do you think I give below the meter does not respond to me. If you help too sevinirim. Thank you in advance
string command;
command ="/?!" (char) 13 (char) 10;
byte [] array;
Array = Encoding.UTF8.GetBytes (command);
serialPort1.Write (array, 0, array.length);
|
|
|
|
|