|
I'm a delphi programmer. I have the same problem when programming, but I find a way to correct it. Take a look at following code which in bold. I hope it can help you.
const
GUID_CLASS_COMPORT: TGUID = (
D1:$86e0d1e0; D2:$8089; D3:$11d0; D4:($9c, $e4, $08, $00, $3e, $30, $1f, $73));
procedure EnumPortsWdm(AList: TStrings);
var
LGuid: TGUID;
LDeviceInfo: HDEVINFO;
LDevice: TSPDevInfoData;
LDeviceInterfaceData: TSPDeviceInterfaceData;
LDeviceInterfaceDetailData: PSPDeviceInterfaceDetailData;
LSuccess, LIsUsbDevice: Boolean;
LDeviceInterfaceDetailDataSize,
LRequiredSize: DWORD;
LIndex: DWORD;
LFriendlyName: array[0..255] of Char;
LDesc: array[0..255] of Char;
LLocInfo: array[0..255] of Char;
LComPortInfo: TComPortInfo;
begin
ClearPortsList(AList);
LGuid := GUID_CLASS_COMPORT;
LDeviceInfo := SetupDiGetClassDevs(@GUID_CLASS_COMPORT,
nil, 0, DIGCF_PRESENT or DIGCF_DEVICEINTERFACE);
if (Cardinal(LDeviceInfo) = INVALID_HANDLE_VALUE) then
begin
Exit;
end;
SetupDiGetDeviceInterfaceDetail(LDeviceInfo,
@LDeviceInterfaceData, nil, 0, @LRequiredSize, @LDevice);
LDeviceInterfaceDetailDataSize := LRequiredSize;
GetMem(LDeviceInterfaceDetailData, LRequiredSize);
try
LDeviceInterfaceData.cbSize := sizeof(TSPDeviceInterfaceData);
LDeviceInterfaceDetailData.cbSize := sizeof(TSPDeviceInterfaceDetailData);
LIndex := 0;
while True do
begin
if not SetupDiEnumDeviceInterfaces(LDeviceInfo,
nil, LGuid, LIndex, LDeviceInterfaceData) then
begin
Break;
end;
LDevice.cbSize := sizeof(TSPDevInfoData);
LDevice.ClassGuid := GUID_CLASS_COMPORT;
if not SetupDiGetDeviceInterfaceDetail(LDeviceInfo,
@LDeviceInterfaceData,
LDeviceInterfaceDetailData,
LDeviceInterfaceDetailDataSize,
@LRequiredSize, @LDevice) then
begin
Break;
end;
LSuccess := SetupDiGetDeviceRegistryProperty(LDeviceInfo,
LDevice, SPDRP_FRIENDLYNAME, nil,
PByte(@LFriendlyName[0]), sizeof(LFriendlyName), nil);
LSuccess := LSuccess and SetupDiGetDeviceRegistryProperty(
LDeviceInfo, LDevice, SPDRP_DEVICEDESC, nil,
PByte(@LDesc[0]), sizeof(LDesc), nil);
LIsUsbDevice := FALSE;
if SetupDiGetDeviceRegistryProperty(
LDeviceInfo, LDevice, SPDRP_LOCATION_INFORMATION, nil,
PByte(@LLocInfo[0]), sizeof(LLocInfo), nil) then
begin
LIsUsbDevice := (Pos('USB', LLocInfo) = 1);
end;
if LSuccess then
begin
LComPortInfo := TComPortInfo.Create;
LComPortInfo.DevPath := PChar(@LDeviceInterfaceDetailData.DevicePath[0]);
LComPortInfo.FriendlyName := LFriendlyName;
LComPortInfo.PortDesc := LDesc;
LComPortInfo.IsUsbDevice := LIsUsbDevice;
AList.AddObject(LFriendlyName, LComPortInfo);
end;
LIndex := LIndex + 1;
end;
finally
FreeMem(LDeviceInterfaceDetailData);
SetupDiDestroyDeviceInfoList(LDeviceInfo);
end;
end;
|
|
|
|
|
Hi All,
I want to design a menu for my applicaiton having looks 100% like windows XP start menu. Can any one give me idea , hoe to do that ? or if already someone has done this then can he/she provide me link?
Thanx in Advance.
sorry for my bad English.
|
|
|
|
|
|
Hi friends
I make a session in asp.net using C# and check the session through glob.aspx.cs
if(session["username"]=="")
{
Resplose.Redirect("Login.aspx");
}
but now i my session is creat on login page if page before login i have to my glob.aspx.cs file check for the session then it generate error that session is not declare Is there any solution to check whether the session is created or not and how to avoid some pages to check the session. suppose i have one page that comes before login name is info.aspx i want that for this page glob.aspx.cs must not be check session is there any way to avoid this page
Thanking You
Hemant Mane
|
|
|
|
|
|
|
How do I add Ctrl+Z character in the end of a string ?
Anyone can help and give the example in C# ?
Thx in advance
|
|
|
|
|
|
lol
Thx Colin... just wanna make sure that Ctrl+Z is 26.
"Courage choose who will follow, Fate choose who will lead" - Lord Gunner, Septerra Core
"Press any key to continue, where's the ANY key ?" - Homer Simpsons
Drinking gives me amazing powers of insight. I can solve all the worlds problems when drunk, but can never remember the solutions in the morning. - Michael P Butler to Paul Watson on 12/08/03
|
|
|
|
|
How to convert data type of chat* to data type of IntPtr(or string)?
Thanks!
|
|
|
|
|
|
Hi!leppie,
Do you have any usb device on hand,such as u-disk,mp3 or cardreader? If you do,then I will send my project to you and you can debug it to see what problem it is.
Thanks!
|
|
|
|
|
|
No!
I really got a problem which tortured me for two days.
What I really want is to settle my problem but never hope others can do job for me.
I had post my problem before this page with title "Error 1784 when invoke SetupDiGetDeviceInterfaceDetail in c#".I see you must a super man,so can you help me out of this problem?
Thanks!
Best Regards!
momer
|
|
|
|
|
momer wrote:
data type of chat*
I'm assuming it's char* , so you might try using Marshal.PtrToStringAuto ?
there are no facts, only interpretations
|
|
|
|
|
......
char* charpoint;
string string1 = Marshal.PtrToStringAuto(charpoint);
It says that char* can not convert to IntPtr.
Thanks!
|
|
|
|
|
What are you trying to do exactly? i thought you where trying to convert a char* u got from some unmanaged source. You should try:
char ch = 'x';
char* charpoint = &ch ;
IntPtr pChar = new IntPtr(charpoint);
string string1 = Marshal.PtrToStringAuto(pChar);
there are no facts, only interpretations
|
|
|
|
|
Hi!yoaz,
Thank you very much I get it.
Thanks you again.
God bless you!
momer
|
|
|
|
|
Hey!
I have a Server/Client program.
The client is sending 4 packages to the Server and the server echo this pacakges back to the client that calculate the time and loose of packages.
I use UDP blocking Connection and threds, like this
byte[] data = new byte[64*1024];<br />
IPAddress addr = Dns.GetHostByName(this.GUI.txtIPAdr.Text).AddressList[0];<br />
dest = new IPEndPoint(addr,int.Parse(this.GUI.txtPort.Text));<br />
iend = dest;<br />
<br />
for(int i = 0; i<4;i++)<br />
{<br />
<br />
this.GUI.lblStatus.Text = "Sending";<br />
<br />
Thread Reciving = new Thread(new ThreadStart(ReciveMessage));<br />
<br />
data = Encoding.Unicode.GetBytes(this.GUI.txtMessage.Text + " " + i.ToString() + " to " + dest.ToString());<br />
<br />
interval = DateTime.Now;<br />
client.SendTo(data,(EndPoint)dest);<br />
Reciving.Start();<br />
<br />
Thread.Sleep(2000);<br />
<br />
if(Reciving.IsAlive)<br />
{<br />
Reciving.Abort();<br />
}<br />
<br />
}<br />
this.GUI.lblStatus.Text = "Stopt";<br />
client.Close();<br />
this.GUI.button1.Enabled = true;
in the ReciveMessage i use
client.ReceiveFrom(data,ref end);
The problem it, if the second packages is lost, then the rest will also be lost, i think that the thread that is running the Recive function the second turn(when there is no answare from the server) is looking then blockt client.ReceiveFrom and there by the other threads cant use this function to get teh pending echo from Server.
Shold i remake to nonBlocking mode? or is there a way to use the Threads better?
The best is if i could close a Thread when the time is finish(thread.sleep(2000)) but Reciving.abort() is not always removed instantly by the garbage collector.
I need the Thread to releas the resurces it got so other threads can use it.
//Jimmy
|
|
|
|
|
Why are you using blocking mode?
And why are you using UDP-Datagrams?
You should rather be sending ICMP-Messages, like "ping" does.
And drop the counter from your "Send-And-Receive"-Loop, you do not know how many replies you will get. That should be in a seperate "send-Thread", if anyhwere.
And yes, I'd rather be using non-blocking socket methods, there is much more flexibility in there.
Oh, and use "Thread.Abort(); Thread.Join();".
Cheers
Sid
|
|
|
|
|
does anyone know how to explain ann's in programming terms since i get natural nn's but not ann's
IM PROUD TO BE A GMAIL;
|
|
|
|
|
there's a series of articles here, starting with this one[^]
there are no facts, only interpretations
|
|
|
|
|
Hi,
I am trying to use a class in multiple projects. It is a simple class containing properties of a given database table. The class, DbTable, is defined in my main DbCompare project. I also want to use this class in a Control Library (UserControl) project which will itself be used in the DbCompare project. However, I am in circular reference hell! When I build the DbCompare project, I get the warning 'DbCompare.DbTable' is defined in multiple places; using definition from 'D:\Proj_net\DbCompare\DbTable.cs'. Does anyone know how to do this?
TIA,
Royce
|
|
|
|
|
If you can re-architect your application I would suggest using events to avoid the circular references.
If you have a layered approach like this:
Presentation
----------------
Business Logic
----------------
Data Abstraction
The Presentation can invoke methods directly in the Business Logic layer, and the Business Logic layer can do the same to the Data Abstraction layer.
However the Data Abstraction layer should know nothing of the Business Logic layer, and the Business Logic layer should know nothing of the Presentation layer.
Think about how the .NET Framework achieves this. The guys at Microsoft know nothing of your application, so the controls fire off events in order to pass messages to your code.
So, If the Data Abstraction layer needs to invoke something in the Business Logic layer it should fire off an event that something in the Business Logic layer subscribes to. Similarly with the Business Logic layer needing to invoke something in the Presentation layer.
Does this help?
Do you want to know more?
|
|
|
|
|
Thanks, Colin.
Yes, I think you have given me some useful ideas.
|
|
|
|
|