|
hi!
What is the correct way to do ti when using multiple threads?
Thanks
Antoine
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
The search button is your friend: clickity[^]
#include "witty_sig.h"
|
|
|
|
|
antoine@orchus-tech wrote:
How can I have the app's main Form(the ui) get modified by those other classes?
How do you modify a form's progress bar from another class?
Your classes are not getting instantiated by the form??? The form could grab this info from the classes after they are created. If you need info established in a class and passed around then you could make that class using the Singleton pattern which involves alot of static methods and getter/setters.
If the form must be modified from outside, then you expose public accessors (getter and setter) for internal fields and pass reference to that form to everyone from the central controller in the app.
antoine@orchus-tech wrote:
How do you modify a form's progress bar from another class?
Go to the C# projects in this site and search for SplashScreen. There is one that is really good and demonstrates the ability of having a smooth status bar based on actual event timings. My class design is as such
main form --> loads main class (contains some static methods etc
main form --> loads splash screen
main form --> calls each init step notifying SplashScreen of event end
main form completes init --> calls SplashScreen with 'all done' event
splash screen goes away.
main form loads MainForm and shows it.
Notice that the main class is still around and everything spawned by the main form has access to that class and its' methods. This is similar to the global thing in VB6 but a purer object approach. Search the net for c# patterns and then check on the Singleton pattern for more info.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Is it not allowed to have unsafe code in an user control that I want to host on a browser? The user control is working properly, and when I compile with the unsafe flag, it stops appearing on the web page. Is there some workaround?
|
|
|
|
|
It depends on the code. There is some stuff that you just cannot do in a browser because it's a security violation. You can't, for instance, P/Invoke code in a .DLL from a browser hosted instance of a control. Manipulating the File System of a client is also a no-no. Let's see a code snippet of what your trying to do and maybe there will be a workaround.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No, it is just turning on the Allow Unsafe Code blocks in the Project Settings page.
My user control has an Image control, and have raw image bits. I am trying to use BitmapData to render the image bits fast. I think this should not pose a security violation.
|
|
|
|
|
The 'unsafe' switch tags you entire assembly as unsafe code. This means, in IE, that your code isn't safe and won't be executed, depending on the security setting your running in IE and the Code Access Security policies you have setup. You'll have to check with the .NET Framework Configuration tool or the Code Access Security Policy tool and make sure that you can run unsafe code from a remote location. By default, you can't run untrusted code from a remote location, like a component loaded from a server.
You can also start by reading Securing Applications[^] for an explanation about how Code Access Security works and why you can't run Unsafe code in IE and how to make it work.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I'm building a custom control from scratch that is sorta hard to describe...kinda like a futuristic combination of a listview and folder view but not really...eh :P
Anyway i want to make it so when you see this control in the designer and click "Items..." in the properties box that you can add stuff using the vs.net menus like you'd see when you add a column or item to a listview.
Not even sure what this sorta scripting or whatever with the ide is called...reason i didn't just google it
|
|
|
|
|
You are about to enter the fun world of custom property descriptors. That is what you google on.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Thx m8
|
|
|
|
|
HI, guys
I am interested in operating USB port in C# . But I don't konw how to do that.
Anybody have some idea about it. Thank you
vigorous
|
|
|
|
|
The .Net framework doesn't allow you to manipulate hardware. You would have to use C++ to accomplish what you want.
Aaron Eldreth
TheCollective4.com
My Articles
While much is too strange to be believed,
Nothing is too strange to have happened.
- T. Hardy
|
|
|
|
|
You can do it with C#, I have working code right here...
This is maddness, I can't believe you said that.
/\ |_ E X E GG
|
|
|
|
|
You'd have to be ALOT more specific about what you want to do. On top of that, how to do it will be vendor and device dependent because you'll be interacting with the driver for that device. Also, since all the NT kernel versions of Windows (NT, 2000, XP, 2003) abstract the hardware, you can't get to the hardware directly. You have to go through either the device driver for the device you want, or write your own device driver that exposes an interface to your managed code (C#).
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Elaborate please.
/\ |_ E X E GG
|
|
|
|
|
In the future, I will need get data from a usb port connected with a bar scanner. The bar scanner will scan a bar graph and send them to the PC by usb. At the moment, I still not know more details about the scanner. So I just want to know some idea about operating usb port.
For example, I know we can use MSCom control or API to control serial port. But how can I use usb port?
If you can provide some code, I will feel very very grateful for your help.
Thank you very much.
vigorous
|
|
|
|
|
Alright, I think I have the idea...
I know microsft already provides generic drivers for scanners, so you can use that instead of the one that comes with the scanner (which is probably proprietry and not documented). SO, you wont' have to write your own driver, thats good.
Um, I suggest you maybe get a development kit, EZ-USB[^]. This will give you some visual results. although it's not necessary. These kits though, come with external memory, a UART and serial connector, a set of push buttons, and an LED readout to facilitate development and debugging of your software. SO, that will help alot in your learning process.
Next you need to learn the fundamentals of USB, like writing to a bus, etc. It's much different then the serial port.
So just wrap the usb functions in c++ and then you can simply call the methods in your c# app/gui. It's a little more complicated then that though.... I have some code if you want to see it.
Actually, everything is in that kit. It's too hard to type all this with one hand. (my wrist is broken.)
/\ |_ E X E GG
|
|
|
|
|
This complies into a nice .net library with 2 main methods (bulk read, write) that I can seamsly use in my C# app. Actually with no pinvoking.
#include "stdafx.h"
#include "csusb.dll"
#include "ezusbsys.h"
#include "usb100.h"
using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices;
namespace EzUsb
{
[StructLayout(LayoutKind::Explicit, Size=18, CharSet=CharSet::Auto)]
public __gc class UsbDeviceDescriptor
{
public:
[FieldOffset(0)] System::Byte bLength;
[FieldOffset(1)] System::Byte bDescriptorType;
[FieldOffset(2)] System::UInt16 bcdUSB;
[FieldOffset(4)] System::Byte bDeviceClass;
[FieldOffset(5)] System::Byte bDeviceSubClass;
[FieldOffset(6)] System::Byte bDeviceProtocol;
[FieldOffset(7)] System::Byte bMaxPacketSize0;
[FieldOffset(8)] System::UInt16 idVendor;
[FieldOffset(10)] System::UInt16 idProduct;
[FieldOffset(12)] System::UInt16 bcdDevice;
[FieldOffset(14)] System::Byte iManufacturer;
[FieldOffset(15)] System::Byte iProduct;
[FieldOffset(16)] System::Byte iSerialNumber;
[FieldOffset(17)] System::Byte bNumConfigurations;
};
public __gc class Usb
{
private:
HANDLE _hEzUsb;
void ReportError( String* msg )
{
if( OnErrorMessage )
{
OnErrorMessage( this, new ErrorEventArgs( msg ) );
}
}
void CheckWin32Error()
{
int errCode = GetLastError();
if( errCode != 0 )
{
char msg[256];
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, errCode, 0,
msg, 256, NULL );
ReportError( msg );
}
}
public:
static const int MaxBlkSize = 64;
__delegate void ErrorMessage( Object* sender, ErrorEventArgs* e );
__event ErrorMessage* OnErrorMessage;
Usb()
{
_hEzUsb = INVALID_HANDLE_VALUE;
}
~Usb()
{
if( _hEzUsb != INVALID_HANDLE_VALUE )
{
CloseHandle( _hEzUsb );
}
}
bool Open( String* driverName )
{
char* lpFileName = new char[driverName->Length + 10];
sprintf( lpFileName, "\\\\.\\%s", driverName );
_hEzUsb = CreateFile( lpFileName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if( _hEzUsb == INVALID_HANDLE_VALUE )
{
CheckWin32Error();
}
delete lpFileName;
return( _hEzUsb != INVALID_HANDLE_VALUE );
}
void Close()
{
CloseHandle( _hEzUsb );
}
Usb::UsbDeviceDescriptor* GetDeviceDescriptor()
{
BOOLEAN success;
ULONG nBytes;
PUSB_DEVICE_DESCRIPTOR pDeviceDiscriptor = new USB_DEVICE_DESCRIPTOR();
if( _hEzUsb == INVALID_HANDLE_VALUE )
{
ReportError( "Driver not open." );
}
else
{
success = DeviceIoControl( _hEzUsb,
IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR,
NULL,
0,
pDeviceDiscriptor,
sizeof(USB_DEVICE_DESCRIPTOR),
&nBytes,
NULL );
if( success == FALSE )
{
CheckWin32Error();
}
}
UsbDeviceDescriptor* DeviceDiscriptor = new UsbDeviceDescriptor();
DeviceDiscriptor = (UsbDeviceDescriptor*)Marshal::PtrToStructure(
pDeviceDiscriptor, DeviceDiscriptor->GetType() );
delete pDeviceDiscriptor;
return( DeviceDiscriptor );
}
System::Byte BulkRead( int pipe ) []
{
if( _hEzUsb == INVALID_HANDLE_VALUE )
{
ReportError( "Driver not open." );
return( 0 );
}
char lpOutBuffer[MaxBlkSize];
BULK_TRANSFER_CONTROL btc;
btc.pipeNum = pipe;
BOOL success;
int nBytes;
success = DeviceIoControl( _hEzUsb,
IOCTL_EZUSB_BULK_READ,
&btc,
sizeof (BULK_TRANSFER_CONTROL),
lpOutBuffer,
MaxBlkSize,
(unsigned long *)&nBytes,
NULL);
if( success == FALSE )
{
CheckWin32Error();
return( 0 );
}
System::Byte buffer __gc[] = new System::Byte[nBytes];
IntPtr ptr( lpOutBuffer );
Marshal::Copy( ptr, buffer, 0, nBytes );
return( buffer );
}
int BulkWrite( System::Byte buffer __gc[], int pipe )
{
if( _hEzUsb == INVALID_HANDLE_VALUE )
{
ReportError( "Driver not open." );
return( 0 );
}
char* lpOutBuffer = new char[buffer->Length];
Marshal::Copy( buffer, 0, lpOutBuffer, buffer->Length );
BULK_TRANSFER_CONTROL btc;
BOOLEAN success;
int nBytes;
btc.pipeNum = pipe;
success = DeviceIoControl( _hEzUsb,
IOCTL_EZUSB_BULK_WRITE,
&btc,
sizeof (BULK_TRANSFER_CONTROL),
lpOutBuffer,
buffer->Length,
(unsigned long *)&nBytes,
NULL);
if( !success )
{
CheckWin32Error();
}
delete lpOutBuffer;
return( nBytes );
}
};
}
/\ |_ E X E GG
|
|
|
|
|
Thank you very much. I am sure your words are very useful and helpful. And I am so sorry to hear about your wrist and hope you will be well quickly.
Best regards
vigorous
|
|
|
|
|
Hey All,
I was just wondering if anybody knows of a "Data Formatting Expression" that I can use with a bound column (of type string) in a datagrid to say something like "If the string is > x characters long, trim it and put '...' at the end"???
Currently I'm manually (i.e. programmatically) checking the lenght and altering the string, if needs be, before the ASP.NET page is rendered which works fine but it's a little slow (and using a formatting expression would be a lot neater) and I can't find a table of formatting expression in the MSDN library.
Any help would be appreciated.
Regards,
Brian Dela
http://www.briandela.com IE 6 required. http://www.briandela.com/pictures Now with a pictures section http://www.briandela.com/rss/newsrss.xml RSS Feed
|
|
|
|
|
There is no Data Formatting Expression for that, simply because it is font and available screen space dependent. The best way to do that is the way your doing it now...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
simply because it is font and available screen space dependent
How is the number of characters in a string font and screen space dependent??? If I have code like this...
string myLovelyHorsey = "A beautiful song from Fr. Ted!";
..the number of characters is the string has nothing to do with font or screen space...
What I wanted to do was not based on the amount of space taken up on screen but based on the number of characters in the string.
Regards,
Brian Dela
http://www.briandela.com IE 6 required. http://www.briandela.com/pictures Now with a pictures section http://www.briandela.com/rss/newsrss.xml RSS Feed
|
|
|
|
|
Mostly, you'll see, what you want to do, is based on the available screen space in a row of a table. Like the Subject field in Outlook when you open your Inbox and have all your messages listed in the right pane, the column the Subject is displayed in can be any width. That width is dependent on the width of the column and the size of font it is displaying.
But, in either case, be it on-screen or simply a maximum number of characters, there is no formatting expression that will cover the functionality you want.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
Mostly, you'll see, what you want to do, is based on the available screen space in a row of a table. Like the Subject field in Outlook when you open your Inbox and have all your messages listed in the right pane, the column the Subject is displayed in can be any width. That width is dependent on the width of the column and the size of font it is displaying
Yep. I understand that... I've wanted to do things like that in the past and have had to do it manually which isn't a problem.
Dave Kreskowiak wrote:
maximum number of characters, there is no formatting expression
yeah. It's a pain.
Regards,
Brian Dela
http://www.briandela.com IE 6 required. http://www.briandela.com/pictures Now with a pictures section http://www.briandela.com/rss/newsrss.xml RSS Feed
|
|
|
|
|
Does someone know where I can find a good explaination of message handling in C#? i.e. how do the PreProcessFilter and WndProc methods work?
Initially I thought that everything in the windows enviroment is plugged into a central message system and PreProcessFilter selects which messages are relevant to a control or form and this gets passed into WndProc and handled. But now I don't think that's right.
Here's an example of what I'm doing. I have a windows form that overrides CreateParams so that it shows like a tooltip or context menu, it won't take focus or activation so I can't use the LostFocus event to close the window when I click off of it. So I figured I would have to override something in the messaging system to do this but I'm a little lost. any ideas?
thanks,
Jesse
|
|
|
|
|