|
Im trying to make a specification here at work for how we should write our classes.
what i mean is for readabillity / make it as easy as possible to find the correct parts of your code.
some might suggest an apporach like this
class
{
//variables
//events
//constructor(s)
//propertis
//methods
//overrides
//interfance implementations
//nested casses
}
or
class
{
//variables
//events
//constructor(s)
//propertis (all propps , overriden propps , interface implemented propps)
//methods (all methods , overriden methods, interface implemented methods)
//nested casses
}
do you guys have any other suggestions?
what about regions ?
i tend to add regions to everything i do , but when im done it usually looks like crap with lots of folded blocks in it.
anyone seen any code that you think "it doesnt get any better than this" (layoutwise/readabillity that is) ??
//Roger
|
|
|
|
|
I've once read the following structure in a book and use it since that time.
All parts are coded as a region and i try not to have more than two nested regions.
class
{
class variables
instance variables
construction, destruction
class methods
instance methods (further grouping depending on what the methods do)
interface implementations
}
www.troschuetz.de
|
|
|
|
|
You've missed constants; I always put them up at the top.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hi all.
I'm trying to use WNetAddConnection2 to connect to a printerqueue on "lpt2:" or to some shared folder on a server on "u:" (or some other "free letter"). I have found several pieces of sample code on the net, and I have a working piece in managed C++, but in c# I get the error "Attempt to access invalid address". From what I understand the program does not recognise the local resource
Some code snippets:
Declarations:
[StructLayout(LayoutKind.Sequential)]
public class NETRESOURCE
{
public long dwScope = 0;
public long dwType = 0;
public long dwDisplayType = 0;
public long dwUsage = 0;
public string lpLocalName = null;
public string lpRemoteName = null;
public string lpComment = null;
public string lpProvider = null;
};
[DllImport("mpr.dll", EntryPoint="WNetAddConnection2")] public static extern int WNetAddConnection2A(NETRESOURCE lpNetResource, string lpPassword, string lpUserName, long dwFlags);
"Working code":
ntRec=new NETRESOURCE();
ntRec.lpRemoteName="\\\\SW\\cn=ADR-HP.ou=Printers.ou=HE.o=SW";
ntRec.dwType=RESOURCETYPE_PRINT;
ntRec.lpLocalName="lpt2:";
ntRec.lpProvider=null;
intRet=WNetAddConnection2A(ntRec, null,null, CONNECT_INTERACTIVE);
The c++ code that works looks like this:
String* pstrPrinter="\\\\SW\\cn=ADR-HP.ou=Printers.ou=HE.o=SW";
String* pstrPort="lpt2:";
TCHAR* pszName=(TCHAR*)(Marshal::StringToHGlobalAnsi(pstrPort)).ToPointer();
TCHAR* pszConn=(TCHAR*)(Marshal::StringToHGlobalAnsi(pstrPrinter)).ToPointer();
ntRec.lpRemoteName=pszConn;
ntRec.dwType=RESOURCETYPE_PRINT;
ntRec.lpLocalName=pszName;
ntRec.lpProvider=NULL;
dwRet=WNetAddConnection2(&ntRec, NULL,NULL, CONNECT_INTERACTIVE);
WNetCancelConnection works in C# thought, just using "lpt2:"
Any good ideas?
Thanks
/EnkelIk
|
|
|
|
|
Hm. What can I say? Going over the code again, and replacing the long with enumerators in NETRESOURCE -I had some problem with these before but I can't quite remember what. Having done this it works like a charm.
Can't believe I have spent hours to solve this!
Sorry for taking your time
Thanks
/EnkelIk
|
|
|
|
|
DWORD values should be passed as either Integer , Int32 , or UInt32 types in VB.ET and Long type in VB6.
VB6 Long = VB.NET Integer
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm reading an Offic 2000 Excel spreadsheet through a c# app and I would like to know the limits of the populated cells, rather than itterating through until I read an empty cell (this is not a good mathod because a sheet can have gaps in it)
Is there a method that will return a single range covering the populated cells?
|
|
|
|
|
To answer my own question:
WorkSheet.UsedRange;
but this range includes cells have formatting, but may be empty.
|
|
|
|
|
Hello NG, I search for information about c# and Nero. i will burn cds with nero version 5.5.x.x. can you help me, how i can start programming.
I've found a tutorial about c# and nero verion 6 and highter, but its not working with earlier versions same 5.5.x.x
thx bjoerg
|
|
|
|
|
Is there anyway to bind the scroll wheel of the mouse to a verticle scrollbar?
For example, in a textbox, if the user "scrolls down" with the middle mouse button, how can I detect that and then update the scrollbar accordingly?
Aaron Eldreth
TheCollective4.com
My Articles
While much is too strange to be believed,
Nothing is too strange to have happened.
- T. Hardy
|
|
|
|
|
To detect scrolling use the MouseWheel event which occurs when the mouse wheel moves while a control has focus.
See the documentation for further information on handling this event.
www.troschuetz.de
|
|
|
|
|
Ahh. Thanks for the info.
Aaron Eldreth
TheCollective4.com
My Articles
While much is too strange to be believed,
Nothing is too strange to have happened.
- T. Hardy
|
|
|
|
|
I am getting
An object reference is required for the nonstatic field, method, or property 'AMPE_Server.AMPE_Service.ReadRequest()'<br /> in the following method.
<br />
private static void ProcessRequest()<br />
{<br />
while ( true )<br />
{<br />
Thread requestThread = new Thread( new ThreadStart( ReadRequest ) );<br />
requestThread.Start();<br />
}<br />
}
which refers to the following method
<br />
private void ReadRequest()<br />
{<br />
AMPE_Server.Communication.Request request = new AMPE_Server.Communication.Request()<br />
lock (this)<br />
{<br />
request = (AMPE_Server.Communication.Request) queueRequests.Dequeue();<br />
}<br />
}
What the hell have I done wrong? This learning threading is hard as hell after programming with VB for the past 10 years.
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!
|
|
|
|
|
private void ReadRequest()
here is your problem:
you need to have a static function to use threads, as they are independent proccess
so write private static void ReadRequest() instead, ofcourse you have to change your code inside the function too since the method is now static.
Hope that helps!
flow
|
|
|
|
|
flow5555 wrote:
you need to have a static function to use threads, as they are independent proccess
That's not the case!
www.troschuetz.de
|
|
|
|
|
Thanks for the help. I redefined the method as static and had to remove the lock code. Can you explain what the lock command does?
Regards,
Eric C. Tomlinson
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!
|
|
|
|
|
This isn't a threading problem and you don't need static methods to use threads.
What you've done wrong is that you pass the ReadRequest method to the ThreadStart delegate without using an object.
<br />
Thread requestThread = new Thread( new ThreadStart( ReadRequest ) );<br />
As the ReadRequest method isn't static this fails. Either declare your method static or use an object.
<br />
Thread requestThread = new Thread( new ThreadStart( obj.ReadRequest ) );<br />
www.troschuetz.de
|
|
|
|
|
I downloaded a project before that uses Crownwood Magic Libraries. I loved the Visual Style IDE that they had for the tab control. Is it possible to use the style that Microsoft uses for Visual Studio.NET in one of my projects?
|
|
|
|
|
Magic Library provides that style. Look at the tab control samples and read the documentation (if he finally provided it like I asked so many times with prior versions).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am trying to write some data to excel 2003 from C#.
I installed windows xp on a machine,visual studio.net and office 2003 from scratch to be sure everything is ok. I also install of course .NET programmability support for the office
I write in C#:
Excel.Application app = new Excel.Application();
app.visible=true;
app.Workbooks.Open("c:/data.xls", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value)
when i run it the first two lines work good and when it goes to the Open function a COMException come up telling me "old format or invalid type library", i also tried _Open function but the same thing happened. If i use an event in the Application object everything works fine,it crashes only when i go to the Workbooks property. PLEASE HELP
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
Did you add an assembly reference to the Office interop assemblies, or use the COM tab to add them? You should do the former. Unfortunately, they're not easy to get at. You must use the command prompt to copy them out of the respective directories in %WINDIR%\assembly\gac (you can't browse to it using Windows Explorer). If you downloaded the PIAs (Primary Interop Assemblies) from MSDN, then you have version 10 (Office XP). If you add a COM reference, then the interop assemblies in the GAC are not used during runtime, but the interop assemblies you generated.
This is a pain, I know, but necessary. Microsoft only installs the Office 2003 assemblies into the GAC and doesn't make them easily accessible for development unless you use the Office project templates in VS.NET 2003.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Could you explain what exactly i have to do, i have to copy the assemblies in my runtime directory form %WINDIR%\assembly\gac and then add a reference to them thru the .NET tab and not the COM tab?
I really appreciate your help
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
You'll need to copy those assemblies somewhere else to use them explicitly without the designer. Start a command prompt (cmd.exe in Windows NT-based OSes) and type:
cd %windir%\assembly\gac
dir You'll see a bunch of directories that match assembly names. You'll need to cd to each of those and then the version (should start with "11.") and copy those assemblies elsewhere, like C:\Program Files\Microsoft.NET\Office11 (recommended, where the Office10 assemblies get their own folder in that directory, which is the parent directory of the default .NET 1.1 SDK).
The important thing is that you use the primary interop assemblies whenever possible.
The way the interop assemblies are registered, however, VS.NET should've used the PIAs already. See, PIAs are typically generated by the company that produced the associated typelib and they are registered so that the typelib registry keys contain and entry that specify the PIAs associated with that typelib, so instead of creating a new typelib the old one is used.
Before you do anything, I would look at the path of the Office assemblies you've already referenced and see if the path is C:\Windows\assembly\gac\....
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I ,finally after lot of search, found what is the problem. It's a bug in office XP and office 2003. When you have installed the english version of office and you regional settings are not the same then you cannot call some functions, especially in Excel, and you have to use InvokeVerb so you tell with what exactly Culture Info you want to call the method. I lost really lot of time searching for this. By the way in office 2003 the PIA work good, you don't have to do the copy you have told, in Office XP there is this problem.
Thanks a lot
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
How is it possible to control the Master, the Wave and the Line-In mixer controls directly?
Help!
----------------------
I think war is a dangerous place.
George W. Bush - Washington DC, May 7th 2003
|
|
|
|